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
投稿

猜你喜欢

  • 微型设计专用工具Dorado

    2011-01-06 12:23:00
  • 互联网产品设计师自我介绍

    2009-04-16 12:45:00
  • MS Server和Oracle中对NULL处理的一些细节差异

    2009-06-10 17:35:00
  • ASP应用:用stream读文件

    2007-09-24 13:33:00
  • 初瞥 Google Chrome Frame

    2009-10-06 14:41:00
  • 通过FSO进行页面计数

    2008-11-27 16:02:00
  • asp 小偷采集程序原理与常用函数方法

    2011-03-06 10:36:00
  • ASP实现文件直接下载的代码

    2011-04-11 10:56:00
  • 新手入门:防范SQL注入攻击的新办法

    2009-03-11 15:14:00
  • 重新认识视觉设计

    2009-09-08 12:46:00
  • 用Mimer Validator检查SQL查询

    2009-04-24 11:59:00
  • 合理利用页面标签元素有利用搜索引擎收录

    2008-11-03 11:49:00
  • Mootools 1.2教程(1)——MooTools介绍

    2008-11-12 13:01:00
  • oracle 日期函数

    2010-07-23 13:32:00
  • MySQL中XML数据的XPath支持

    2009-12-15 21:57:00
  • 数据库连接字符串的常见问题和解决方法

    2008-11-28 15:16:00
  • 交互设计杂七杂八

    2010-09-25 18:41:00
  • 提高MySQL数据库查询效率的三个实用技巧

    2008-12-03 16:40:00
  • 利用XMLBean轻轻松松读写XML

    2008-09-04 11:25:00
  • 在ASP中使用SQL语句之9:表单操作

    2007-08-11 13:18:00
  • asp之家 网络编程 m.aspxhome.com