XMLHttp ASP远程获取网页内容代码
2008-11-10 00:00
627 查看
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
相关文章推荐
- asp获取远程网页的指定内容的实现代码
- asp获取远程网页的指定内容的实现代码
- asp获取远程网页的指定内容的实现代码
- asp.net(C#) 远程获取网页内容代码分享
- asp中利用xmlhttp抓取网页内容的代码
- PHP 获取远程网页内容的代码(fopen,curl已测)
- asp.net中获取远程网页的内容之一(downmoon原创)
- Asp.NET XMLHTTP获取网页内容C#版
- [PHP代码] PHP远程获取网页内容
- asp.net 获取远程网页内容
- PHP 获取远程网页内容的代码(fopen,curl已测)
- 分享几段获取远程网页内容的php代码。
- VB使用xmlhttp获取远程网页内容
- php 获取远程网页内容的函数
- javascript使用xmlhttp获取网页内容