主页 > 知识库 > XMLHttp ASP远程获取网页内容代码

XMLHttp ASP远程获取网页内容代码

热门标签:电子围栏 阿里云 银行业务 Mysql连接数设置 科大讯飞语音识别系统 Linux服务器 服务器配置 团购网站

复制代码 代码如下:

url="http://www.csdn.net/"
wstr=getHTTPPage(url)
start=Newstring(wstr,"资源精选!-- 下载 -->")
over=Newstring(wstr,"div class=""friendlink"">")
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

标签:大理 广元 江苏 衡水 萍乡 枣庄 衢州 蚌埠

巨人网络通讯声明:本文标题《XMLHttp ASP远程获取网页内容代码》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266