国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 延安市| 化州市| 淄博市| 内黄县| 明光市| 山阳县| 高台县| 尼木县| 赤峰市| 肃南| 蚌埠市| 保康县| 江都市| 汶上县| 额尔古纳市| 和平区| 永宁县| 临海市| 湘乡市| 沿河| 岱山县| 武宁县| 鄂伦春自治旗| 城口县| 辛集市| 博野县| 苍梧县| 大方县| 梁河县| 兴安县| 文安县| 扶绥县| 锦州市| 雷山县| 北安市| 霸州市| 杭锦后旗| 龙泉市| 杭州市| 宜兴市| 长治县|