asp 利用 xmlhttp 抓取网页内容

分类:网站技术 | lao8发表于 2008-1-4 15:02:00

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换成我们想要抓取的网页地址即可

标签:xmlhttp 抓取
收藏到收藏夹

相关"xmlhttp 抓取"文章


username(必填) email(必填) website

站内搜索

 

按分类归档

lao8 最新文章: