国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

自己做采集程序

2024-05-04 11:03:14
字體:
供稿:網(wǎng)友

現(xiàn)在網(wǎng)上的采集程序很多,但是有時(shí)候你發(fā)現(xiàn)一個(gè)好的網(wǎng)站,想自己做個(gè)采集工具采集一些信息,就需要自己去寫程序了,其實(shí)這樣的采集程序并不難寫,主要是去分析源網(wǎng)站的網(wǎng)頁結(jié)構(gòu)。
首先去下載個(gè)XMLHTTP的類文件:
<%
Class xhttp
private cset,sUrl,sError
Private Sub Class_Initialize()
'cset="UTF-8"
cset="GB2312"
sError=""
end sub

Private Sub Class_Terminate()
End Sub

Public Property LET URL(theurl)
sUrl=theurl
end property
public property GET BasePath()
BasePath=mid(sUrl,1,InStrRev(sUrl,"/")-1)
end property
public property GET FileName()
FileName=mid(sUrl,InStrRev(sUrl,"/")+1)
end property
public property GET Html()
Html=BytesToBstr(getBody(sUrl))
end property

public property GET xhttpError()
xhttpError=sError
end property

private Function BytesToBstr(body)
on error resume next
'Cset:GB2312 UTF-8
dim objstream
set objstream = Server.CreateObject("adodb.stream")
with objstream
.Type = 1 '
.Mode = 3 '
.Open    
.Write body  '
.Position = 0 '
.Type = 2  '
.Charset = Cset  '
BytesToBstr = .ReadText '
.Close
end with
set objstream = nothing
End Function

private function getBody(surl)
on error resume next
dim xmlHttp
'Set xmlHttp=server.createobject("Msxml2.XMLHTTP.4.0")
'set xmlHttp=server.createobject("Microsoft.XMLHTTP")
set xmlHttp=server.createobject("MSXML2.ServerXMLHTTP")
xmlHttp.setTimeouts 10000,10000,10000,30000
xmlHttp.open "GET",surl,false
xmlHttp.send
if xmlHttp.readystate=4 then
'if xmlHttp.status=200 then
 getBody=xmlhttp.responsebody
'end if
 else
 getBody=""
end if

if Err.Number<>0 then
sError=Err.Number
Err.clear
else
sError=""
end if
set xmlHttp=nothing
end function

Public function saveimage(tofile,isoverwrite)
on error resume next
dim objStream,objFSO,imgs

if Not isoverwrite Then
 Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
 If objFSO.FileExists(Server.MapPath(tofile)) Then
  Exit Function
 End If
 Set objFSO = Nothing
End IF

imgs=getBody(sUrl)
Set objStream = Server.CreateObject("ADODB.Stream")
with objStream
.Type =1
.Open
.write imgs
.SaveToFile server.mappath(tofile),2
.Close()
end with
set objstream=nothing
end function

end class

%>
用了這個(gè)類文件,做起事情來就方便多了。
然后就可以分析采集網(wǎng)站的網(wǎng)頁結(jié)構(gòu),寫采集程序了。
下面給個(gè)例子:
<!--#include file="conn.asp"-->
<!--#include file="inc/xhttp_class.asp"-->
<!--#include file="inc/function.asp"-->
<%
server.ScriptTimeout = 1000
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>BT采集器</title>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 无锡市| 肇源县| 田林县| 涿鹿县| 荣成市| 顺平县| 昭苏县| 于都县| 海原县| 伊吾县| 汶上县| 彭州市| 兴海县| 和田市| 弥渡县| 泸西县| 英山县| 青田县| 玉溪市| 西乌珠穆沁旗| 千阳县| 金乡县| 平山县| 荣成市| 临沭县| 尤溪县| 云梦县| 象州县| 昭平县| 大渡口区| 隆化县| 安多县| 仁怀市| 五河县| 西青区| 天门市| 秭归县| 揭阳市| 阿勒泰市| 当涂县| 闸北区|