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

来源:asp之家 时间:2011-04-10 10:41:00 


代码如下:


url="http://www.cidianwang.com/" 
wstr=getHTTPPage(url) 
start=Newstring(wstr,"词典网") 
over=Newstring(wstr,"</div>") 
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
0
投稿

猜你喜欢

  • 基于python实现简单网页服务器代码实例

    2023-06-26 07:56:44
  • mysql5.58的编译安装

    2011-01-29 16:26:00
  • python是先运行metaclass还是先有类属性解析

    2022-02-10 23:24:48
  • Python设计模式之MVC模式简单示例

    2023-02-24 16:58:33
  • JavaScript实现QQ聊天室功能

    2024-04-19 09:47:53
  • python3 实现爬取TOP500的音乐信息并存储到mongoDB数据库中

    2024-01-21 06:11:12
  • 部署ASP.NET Core程序到Windows系统

    2024-05-09 09:04:38
  • ASP实例:使用ASP生成图片彩色校验码

    2009-01-20 16:27:00
  • pyinstaller打包python3.6和PyQt5中各种错误的解决方案汇总

    2021-01-13 18:58:48
  • python目标检测IOU的概念与示例

    2022-04-19 07:41:25
  • Python 调用C++封装的进一步探索交流

    2022-10-29 22:43:43
  • Python使用requests发送POST请求实例代码

    2022-10-26 07:40:00
  • HTML+JS实现猜拳游戏的示例代码

    2024-04-16 09:31:25
  • 详解php中implode explode serialize json msgpack性能对比

    2023-09-03 18:00:19
  • 安装MySQL的步骤和方法

    2009-07-30 08:38:00
  • 一文总结MySQL中数学函数有哪些

    2024-01-28 11:24:09
  • js拖动div 当鼠标移动时整个div也相应的移动

    2024-04-22 22:17:20
  • Python中使用sklearn进行特征降维的方法

    2021-09-20 06:23:50
  • 使用Python开发SQLite代理服务器的方法

    2021-01-27 13:10:31
  • Linux系统(CentOS)下python2.7.10安装

    2021-04-02 19:27:50
  • asp之家 网络编程 m.aspxhome.com