asp抓取html,XMLHttp ASP远程获取网页内容代码

url="http://www.csdn.net/"

wstr=getHTTPPage(url)

start=Newstring(wstr,"资源精选")

over=Newstring(wstr,"

")

body=mid(wstr,200,500)

response.write body

Function getHTTPPage(url)

dim objXML

set objXML=createobject("MSXML2.XMLHTTP")'定义

objXML.open "GET",url,false'打开

objXML.send()'发送

If objXML.readystate<>4 then '判断文档是否已经解析完,以做客户端接受返回消息

exit function

End If

getHTTPPage=bBytesToBstr(objXML.responseBody)'返回信息,同时用函数定义编码

set objXML=nothing'关闭

if err.number<>0 then err.Clear

End Function

Function Newstring(wstr,strng)

Newstring=Instr(lcase(wstr),lcase(strng))

if Newstring<=0 then Newstring=Len(wstr)

End Function

Function bBytesToBstr(body)

dim objstream

set objstream = CreateObject("adodb.stream")

objstream.Type = 1

objstream.Mode =3

objstream.Open

objstream.Write body

objstream.Position = 0

objstream.Type = 2

objstream.Charset = "gb2312"

'转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码

bBytesToBstr = objstream.ReadText

objstream.Close

set objstream = nothing

end Function

Function BytesToBstr(body)

dim objstream

set objstream = CreateObject("adodb.stream")

objstream.Type = 1

objstream.Mode =3

objstream.Open

objstream.Write body

objstream.Position = 0

objstream.Type = 2

objstream.Charset = "utf-8"

'转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码

BytesToBstr = objstream.ReadText

objstream.Close

set objstream = nothing

end Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>