ASP代理采集的核心函数代码
来源:asp之家 时间:2010-01-02 20:43:00
asp代理采集代码如下:
<%
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.aspxhome.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
%>
代码解释:
1、如果系统是win 2003,只能使用以下代码:
CreateObject("MSXML2.ServerXMLHTTP.4.0")
如果是xp,则使用:
CreateObject("MSXML2.ServerXMLHTTP.5.0")