asp 利用 xmlhttp 抓取网页内容
asp 可以用xml http 抓取其它网页内容,这就是所谓的“小偷程序”,核心代码如下:
<%'使用xmlhttp抓取网页内容
function getbody(url)
dim objxml
on error resume next
set objxml = createobject("microsoft.xmlhttp")
with objxml
.open "get", url, false, "", ""
.send
getbody = .responsebody
end with
getbody=bytestobstr(getbody,"gb2312")'我们采用gb2312简体中文编码,可以换成你需要的编码格式
set objxml = nothing
end function
'adodb.stream处理二进制数据,解决xmlhttp抓取乱码
function bytestobstr(strbody,codebase)
dim objstream
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.mode =3
objstream.open
objstream.write strbody
objstream.position = 0
objstream.type = 2
objstream.charset = codebase
bytestobstr = objstream.readtext
objstream.close
set objstream = nothing
end function
response.write getbody(url)
%>
把 “response.write getbody(url)”中url换成我们想要抓取的网页地址即可
- 来源:转载
- 版权声明:请尊重原作者的版权,转载请注明作者、出处(老吧)。
- 本文链接地址:http://www.lao8.org/html/8/2008-1-4/200814150157.html
- 文章名:asp 利用 xmlhttp 抓取网页内容



