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過程,你采集的時候可以定義網頁是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
代碼解釋:
如果你系統是win 2003 只能使用以下代碼
CreateObject("MSXML2.ServerXMLHTTP.4.0")
若為xp
CreateObject("MSXML2.ServerXMLHTTP.5.0")
偽造referer用處很一般,不過對於一些站還是有用的,所以代碼我加上了,可以注釋掉,
注意:
如果你不會寫asp采集,那麼代碼你可能不懂,那就不是我這次發帖所討論了,希望對大家有用。