html5中文学习网

您的位置: 首页 > 网络编程 > ASP编程 » 正文

asp抓取页面_ASP教程_编程技术

[ ] 已经帮助:人解决问题
  1. <
  2.  
  3. if trim(request.form("url"))<>"" then 
  4.  
  5. dim VBody:VBody=GetResStr(trim(request.form("url"))) 
  6.  
  7. dim Res:Res=VBody 
  8.  
  9. dim code:code=GetCode(VBody,"charset= {0,}([^ ]+) {0,}""") 
  10.  
  11. end if 
  12.  
  13. %> 
  14.  
  15. <html> 
  16.  
  17. <head> 
  18.  
  19. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
  20.  
  21. <title>抓取页面</title> 
  22.  
  23. </head> 
  24.  
  25. <body style="font-size:12px;margin:50px 0 0 20px;"> 
  26.  
  27. <form name="geturl" action="ss.asp" method="post"> 
  28.  
  29. 请输入%20name=" type=text value="<%=trim(request.form(" P >>< <input > url?))%>size="60" url?> 
  30.  
  31. </form> 
  32.  
  33. 页面编码:<%=code%> <br /> 
  34.  
  35. <textarea cols=150 rows=30><%=Res%></textarea> 
  36.  
  37. </body> 
  38.  
  39. </html> 
  40.  
  41. <
  42.  
  43. function GetResStr(URL) 
  44.  
  45. dim ResBody,ResStr,PageCode 
  46.  
  47. Set Http=server.createobject("msxml2.serverxmlhttp.3.0") 
  48.  
  49. Http.setTimeouts 10000, 10000, 10000, 10000 
  50.  
  51. Http.open "GET",URL,False 
  52.  
  53. Http.Send() 
  54.  
  55. If Http.Readystate =4 Then 
  56.  
  57.   If Http.status=200 Then 
  58.  
  59.     ResStr=http.responseText 
  60.  
  61.     ResBody=http.responseBody 
  62.  
  63.     PageCode=replace(GetCode(ResStr,"charset=([^/""].*)"""),chr(13)&chr(10),"") 
  64.  
  65.     GetResStr=BytesToBstr(http.responseBody,trim(PageCode)) 
  66.  
  67.   End If 
  68.  
  69. End If 
  70.  
  71. End Function 
  72.  
  73. '函数名:BytesToBstr 
  74.  
  75. '作用:转换二进制数据为字符 
  76.  
  77. '参数:Body-二进制数据,Cset-文本编码方式 
  78.  
  79. Function BytesToBstr(Body,Cset) 
  80.  
  81.   Dim Objstream 
  82.  
  83.   Set Objstream = Server.CreateObject("adodb.stream") 
  84.  
  85.   objstream.Type = 1 
  86.  
  87.   objstream.Mode =3 
  88.  
  89.   objstream.Open 
  90.  
  91.   objstream.Write body 
  92.  
  93.   objstream.Position = 0 
  94.  
  95.   objstream.Type = 2 
  96.  
  97.   objstream.Charset = Cset 
  98.  
  99.   BytesToBstr = objstream.ReadText 
  100.  
  101.   objstream.Close 
  102.  
  103.   set objstream = nothing 
  104.  
  105. End Function 
  106.  
  107.   
  108.  
  109. '函数名:GetCode 
  110.  
  111. '作用:转换二进制为字符 
  112.  
  113. '参数:str-待查询字符串,regstr-正则表达式 
  114.  
  115. Function GetCode(str,regstr) 
  116.  
  117. Dim Reg 
  118.  
  119. set Regnew RegExp 
  120.  
  121. Reg.IgnoreCase = True 
  122.  
  123. Reg.MultiLine = True 
  124.  
  125. Reg.Pattern =regstr 
  126.  
  127. Set Cols = Reg.Execute(str) 
  128.  
  129. str=Cols(0).SubMatches(0) 
  130.  
  131. GetCode=str 
  132.  
  133. end function 
  134.  
  135. %> 
本文链接http://www.cxybl.com/html/wlbc/Asp/20120613/29966.html
ftyHTML5中文学习网 - HTML5先行者学习网
ftyHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助