asp抓取网页的方法1
代码如下
<%
function getHTTPPage(url) '通过组件Msxml2.XMLHTTP抓取网页内容
on error resume next
dim http
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "get",url,false
Http.send()
if Http.readystate<>4 then exit function
getHTTPPage=bytes2BSTR(Http.responseBody)
set http=nothing
if err.number<>0 then err.Clear
end function
Function bytes2BSTR(vIn) '把抓取到的内容转化为文本
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode<&H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
dim xurl
xurl="http://www.chinadxscy.com/news/html/20070628201930.html"
strContent=getHTTPPage(xurl)
response.write(strContent)
%>
<%
function getHTTPPage(url) '通过组件Msxml2.XMLHTTP抓取网页内容
on error resume next
dim http
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "get",url,false
Http.send()
if Http.readystate<>4 then exit function
getHTTPPage=bytes2BSTR(Http.responseBody)
set http=nothing
if err.number<>0 then err.Clear
end function
Function bytes2BSTR(vIn) '把抓取到的内容转化为文本
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode<&H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
dim xurl
xurl="http://www.chinadxscy.com/news/html/20070628201930.html"
strContent=getHTTPPage(xurl)
response.write(strContent)
%>

浙公网安备 33010602011771号