현재 온라인으로 많은 컬렉션 프로그램이 있지만 때로는 좋은 웹 사이트를 찾고 정보를 수집 할 수있는 컬렉션 도구를 만들고 싶을 때 프로그램을 직접 작성해야합니다. 실제로, 그러한 수집 프로그램은 글을 쓰기가 어렵지 않습니다. 주로 소스 웹 사이트의 웹 구조를 분석합니다.
먼저 XMLHTTP 클래스 파일을 다운로드하십시오.
<%
클래스 XHTTP
개인 CSET, SURL, SERROR
private sub class_initialize ()
'cset = "utf-8"
CSET = "GB2312"
Serror = ""
종료 서브
private sub class_terminate ()
종료 서브
공공 재산 let url (theurl)
surl = therl
종료 속성
공공 재산은 Basepath ()를 얻습니다.
Basepath = mid (Surl, 1, Instrev (Surl, "/") -1)
종료 속성
공공 부동산 get filename ()
filename = mid (surl, instrev (surl, "/")+1)
종료 속성
공공 부동산 GET HTML ()
html = bytestobstr (getbody (surl))
종료 속성
공공 부동산 get xhttperror ()
xhttperror = Serror
종료 속성
개인 기능 bytestobstr (Body)
다음에 오류가 재개됩니다
'CSET : GB2312 UTF-8
희미한 objstream
set objstream = server.createobject ( "adodb.stream")
objstream과 함께
.type = 1 '
. 모드 = 3 '
.열려 있는
. 쓰기 '
.Position = 0 '
.type = 2 '
.charset = cset '
bytestobstr = .readText '
.닫다
끝납니다
objstream = 아무것도 설정하지 않습니다
엔드 기능
개인 기능 getbody (surl)
다음에 오류가 재개됩니다
Dim XMLHTTP
'set xmlhttp = server.createobject ( "msxml2.xmlhttp.4.0")
'set xmlhttp = server.createobject ( "microsoft.xmlhttp")
set xmlhttp = server.createobject ( "msxml2.serverxmlhttp")
XMLHTTP. 세트 타임 아웃 10000,10000,10000,30000
xmlhttp.open "get", surl, false
xmlhttp.send
xmlhttp.readystate = 4 인 경우
'xmlhttp.status = 200이면
getbody = xmlhttp.responsebody
'끝 If
또 다른
getbody = ""
끝 If
err.number <> 0 인 경우
Serror = err.number
err.clear
또 다른
Serror = ""
끝 If
xmlhttp = 아무것도 설정하지 않습니다
엔드 기능
공개 기능 SaveImage (Tofile, Isoverwrite)
다음에 오류가 재개됩니다
Dim objstream, objfso, imgs
Isoverwrite가 아니라면
set objfso = server.createobject ( "scripting.filesystemobject")
if objfso.fileExists (server.mappath (tofile))
종료 기능
끝 If
OBJFSO = 아무것도 설정하지 않습니다
끝 If
imgs = getbody (surl)
set objstream = server.createobject ( "adodb.stream")
objstream과 함께
.type = 1
.열려 있는
. imgs를 쓰십시오
.savetofile server.mappath (tofile), 2
.닫다()
끝납니다
objstream = 아무것도 설정하지 않습니다
엔드 기능
수업 종료
%>
이 유형의 파일을 사용하면 작업을 수행하는 것이 훨씬 편리합니다.
그런 다음 컬렉션 웹 사이트의 웹 페이지 구조를 분석하고 컬렉션 프로그램을 작성할 수 있습니다.
예는 다음과 같습니다.
<!-#포함 파일 = "conn.asp"->
<!-#include file = "inc/xhttp_class.asp"->
<!-#include file = "inc/function.asp"->
<%
Server.ScriptTimeout = 1000
%>
<html>
<헤드>
<meta http-equiv = "content-type"content = "text /html; charset = gb2312" />
<title> bt 수집기 </title>