asp代理采集的核心函數(shù)代碼
更新時(shí)間:2008年10月04日 23:53:35 作者:
如果你不會(huì)寫asp采集,那么代碼你可能不懂,那就不是我這次發(fā)帖所討論了,希望對(duì)大家有用。
Function ProxyPage(url)
Set Retrieval = CreateObject("MSXML2.ServerXMLHTTP.5.0")
With Retrieval
.SetProxy 2 , "255.0.0.0:80" '代理ip:代理端口
.Open "Get", url, False, "", ""
.setRequestHeader "Referer","http://www.baidu.com/" '偽造referer
.Send
ProxyPage = BytesToBstr(.ResponseBody)
End With
Set Retrieval = Nothing
End Function
附BytesToBstr過程,你采集的時(shí)候可以定義網(wǎng)頁是utf-8還是gb2312,utf="True"為 utf-8
Function BytesToBstr(body)
dim objstream
set objstream = Server.CreateObject("ad"&""&"odb.st"&""&"ream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
if utf="True" then
objstream.Charset = "utf-8"
else
objstream.Charset = "gb2312"
end if
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
代碼解釋:
如果你系統(tǒng)是win 2003 只能使用以下代碼
CreateObject("MSXML2.ServerXMLHTTP.4.0")
若為xp
CreateObject("MSXML2.ServerXMLHTTP.5.0")
偽造referer用處很一般,不過對(duì)于一些站還是有用的,所以代碼我加上了,可以注釋掉,
注意:
如果你不會(huì)寫asp采集,那么代碼你可能不懂,那就不是我這次發(fā)帖所討論了,希望對(duì)大家有用。
Set Retrieval = CreateObject("MSXML2.ServerXMLHTTP.5.0")
With Retrieval
.SetProxy 2 , "255.0.0.0:80" '代理ip:代理端口
.Open "Get", url, False, "", ""
.setRequestHeader "Referer","http://www.baidu.com/" '偽造referer
.Send
ProxyPage = BytesToBstr(.ResponseBody)
End With
Set Retrieval = Nothing
End Function
附BytesToBstr過程,你采集的時(shí)候可以定義網(wǎng)頁是utf-8還是gb2312,utf="True"為 utf-8
Function BytesToBstr(body)
dim objstream
set objstream = Server.CreateObject("ad"&""&"odb.st"&""&"ream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
if utf="True" then
objstream.Charset = "utf-8"
else
objstream.Charset = "gb2312"
end if
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
代碼解釋:
如果你系統(tǒng)是win 2003 只能使用以下代碼
CreateObject("MSXML2.ServerXMLHTTP.4.0")
若為xp
CreateObject("MSXML2.ServerXMLHTTP.5.0")
偽造referer用處很一般,不過對(duì)于一些站還是有用的,所以代碼我加上了,可以注釋掉,
注意:
如果你不會(huì)寫asp采集,那么代碼你可能不懂,那就不是我這次發(fā)帖所討論了,希望對(duì)大家有用。
相關(guān)文章
Asp定時(shí)執(zhí)行操作 Asp定時(shí)讀取數(shù)據(jù)庫(網(wǎng)頁定時(shí)操作詳解)
由于目前部分網(wǎng)頁語言的限制,在定時(shí)操作上有一定的困難,但是經(jīng)過我多次的求證,發(fā)現(xiàn)第四種方法無疑是效果最好的,最省心的。2009-10-10遠(yuǎn)程圖片自動(dòng)按文件夾上傳到服務(wù)器-默飛出品
遠(yuǎn)程圖片自動(dòng)按文件夾上傳到服務(wù)器-默飛出品...2006-06-06利用MSXML2.XmlHttp和Adodb.Stream采集圖片
asp下經(jīng)常用來采集的兩個(gè)組件結(jié)合使用例子2008-05-05