当前位置: 首页 > 图文教程 > 网络编程 > ASP > XMLHttp ASP远程获取网页内容代码

ASP
asp OpenTextFile文本读取与写入实例代码
在ASP编程中nothing代表什么意思?
asp之让Session永不过期
ASP获取ACCESS数据库表名及结构的代码
推荐一篇不错的新手asp编程的基本法则
最简洁的asp多重查询的解决方案
ASP 判断是否有中文的代码
asp.net常用函数收藏
asp下几种常用排序算法
asp获取数据库中表名和字段名的代码
简单的asp采集代码教程
asp生成带有样式的word文件方法
实用301转向到另一域名相应页面的asp代码
asp伪继承初探_实例代码
asp代理采集的核心函数代码
js table排序类代码
ASP UTF-8页面乱码+GB2312转UTF-8 +生成UTF-8格式的文件(编码)
Asp生成RSS的类_给网站加上RSS
utf-8 网页不显示+utf-8网页乱码的通用解决方法
asp截取指定英汉混合字符串_支持中文

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 29 ::
收藏到网摘: n/a

asp下利用xmlhttp获取网页内容的方法这个方法一般比较通用的,然后通过字符截取网页的内容。

复制代码 代码如下:

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