| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 455 人关注过本帖
标题:Asp利用XmlHttp采集网页数据
只看楼主 加入收藏
VB爱上我
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:478
专家分:52
注 册:2005-10-14
结帖率:100%
收藏
 问题点数:0 回复次数:0 
Asp利用XmlHttp采集网页数据
<%
On Error Resume Next
Server.ScriptTimeOut=300
function getHTTPPage(Path)
        t = GetBody(Path)
        getHTTPPage=BytesToBstr(t,"GB2312")
end function

function GetBody(url)
        'on error resume next
        Set Retrieval = CreateObject("Microsoft.XMLHTTP")
        With Retrieval
        .Open "Get", url, False, "", ""
        .Send
        GetBody = .ResponseBody
        end With
        Set Retrieval = Nothing
end function

function BytesToBstr(body,Cset)
        dim objstream
        set objstream = Server.CreateObject("adodb.stream")
        objstream.Type = 1
        objstream.Mode =3
        objstream.Open
        objstream.Write body
        objstream.Position = 0
        objstream.Type = 2
        objstream.Charset = Cset
        BytesToBstr = objstream.ReadText
        objstream.Close
        set objstream = nothing
end function

'------------------------------------------------------------
'获取源字符串中以某字符串开始并且以某字符串结束,中间的那段字符串
'SourceStr : 源字符串
'BeginStr : 开始字符串
'EndStr : 结束字符串
'WithB : 是否包含开始字符串(1代表包含0代表不包含)
'WithE : 是否包含结束字符串(1代表包含0代表不包含)
'说明:开始字符串一定要保证是唯一字符串,否则会是在源字符串中第一次出现的那个位置
'-----------------------------------------------------------------------------
function GetMidWith(byval SourceStr,BeginStr,EndStr,WithB,WithE)
 dim bIndex
 bIndex = instr(SourceStr,BeginStr)
 if bIndex <= 0 then GetMidWith = "":exit function
 
 SourceStr = mid(SourceStr,bIndex + len(BeginStr))'不包含开始字符串
 
 bIndex = instr(SourceStr,EndStr)
 if bIndex <= 0 then GetMidWith = SourceStr:exit function

 if WithE = 1 then
  GetMidWith = mid(SourceStr,1,bIndex + len(EndStr) - 1)'包含结束字符串
 else
  GetMidWith = mid(SourceStr,1,bIndex-1)'不包含结束字符串
 end if
 
 
 if WithB = 1 then GetMidWith = BeginStr & GetMidWith'包含开始字符串
end function

'------------------------------------------------------------
'获取源字符串中以某字符串开始并且以某字符串结束,中间的那段字符串
'SourceStr : 源字符串
'BeginStr : 开始字符串
'EndStr : 结束字符串
'WithB : 是否包含开始字符串(1代表包含0代表不包含)
'WithE : 是否包含结束字符串(1代表包含0代表不包含)
'说明:开始字符串与结束字符串一定要保证是唯一字符串
'-----------------------------------------------------------------------------
function GetMid(byval SourceStr,BeginStr,EndStr,WithB,WithE)
 dim bIndex
 dim eIndex

 bIndex = instr(SourceStr,BeginStr)
 eIndex = instr(SourceStr,EndStr)
 if bIndex <= 0 or eIndex <= 0 or eIndex - bIndex<=0 then GetMid = "":exit function
 
 if WithB = 1 then
  if WithE = 1 then
   GetMid = mid(SourceStr,bIndex,eIndex + len(EndStr) - bIndex)'包含开始字符串 包含结束字符串
  else
   GetMid = mid(SourceStr,bIndex,eIndex - bIndex)'包含开始字符串 不包含结束字符串
  end if
 else
  if WithE = 1 then
   GetMid = mid(SourceStr,bIndex + len(BeginStr),eIndex + len(EndStr) - bIndex - len(BeginStr))'不包含开始字符串 包含结束字符串
  else
   GetMid = mid(SourceStr,bIndex + len(BeginStr),eIndex - len(BeginStr) - bIndex)'不包含开始字符串 不包含结束字符串
  end if
 end if
end function
%>

<html>

<BODY bgColor=#ffffff leftMargin=0 topMargin=0 MARGINHEIGHT=0 MARGINWIDTH=0>
<!-- 开始 -->   
<%
Dim url

url="http://www.baidu.com/"
response.Write GetMidWith(getHTTPPage(url),"<input type=""submit""","</span>",1,0)
%>
<!-- 结束 -->
</body></html>

原文:http://
搜索更多相关主题的帖子: False 
2011-10-29 22:04
快速回复:Asp利用XmlHttp采集网页数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013855 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved