<%
function getPage(url)
on error resume next
dim http
set http=Server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getPage=bytes2BSTR(Http.responseBody)
set http=nothing
if err.number<>0 then err.Clear
end function
Function bytes2BSTR(vIn)
dim strReturn
dim i1,ThisCharCode,NextCharCode
strReturn = ""
For i1 = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i1,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i1+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i1 = i1 + 1
End If
Next
bytes2BSTR = strReturn
End Function
%>
ASP中的XMLHTTP封装
最新推荐文章于 2021-08-05 22:19:05 发布
本文介绍了一种使用VBS脚本语言获取并解析网页内容的方法。通过创建Microsoft.XMLHTTP对象发送GET请求来抓取指定URL的网页,然后利用自定义函数将获取到的二进制数据转换为字符串形式。该技术适用于简单的网页爬虫开发或数据抓取场景。
1861

被折叠的 条评论
为什么被折叠?



