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

ASP
asp下查询xml的实现代码
一个asp版XMLDOM操作类
ASP XML编程objXML.async = False
asp按关键字查询XML的代码
asp下用fso和ado.stream写xml文件的方法
SQL"不能为新插入的行确定标识"错误的解决方法
asp 类型转换函数大全
ASP存储过程开发应用详解
asp 静态页面的另一种思路
EasyASP v1.5发布(包含数据库操作类,原clsDbCtrl.asp)
ASP访问数量统计代码
asp中文数字验证码
Ajax+asp应用实例 注册模块,表单提交
将ASP记录集输出成n列的表格形式显示的方法
ASP 游标参数详解(ASP记录集)
关于ASP循环表格的问题之解答[比较详细]
ASP Recordset 分页显示数据的方法(修正版)
ASP ajax分页教程一
Asp Oracle存储过程返回结果集的代码
XMLHttp ASP远程获取网页内容代码

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 28 ::
收藏到网摘: 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