查看: 1090|回复: 0

[文章教程] 远程抓取网页源代码ASP版

[复制链接]
ttasp 发表于 2019-8-20 15:34:05 | 显示全部楼层 |阅读模式
  1. <%
  2. Function getHTTPPage(url)
  3.     dim http
  4.     set http=Server.createobject("Msxml2.ServerXMLHTTP")
  5.     Http.open "GET",url,false
  6.     Http.send()
  7.     if Http.readystate<>4 then
  8.        exit function
  9.     end if
  10.     if (RegExpTest("utf",http.ResponseText))=1 Then
  11.         getHTTPPage=http.ResponseText
  12.     else
  13.            Cset="gb2312"
  14.            getHTTPPage=Http.ResponseText
  15.     End if
  16.     set http=nothing
  17.     if err.number<>0 then err.Clear  
  18. End function
  19. Function RegExpTest(patrn, strng)
  20.   Dim regEx, retVal
  21.   Set regEx = New RegExp
  22.   regEx.Pattern = patrn
  23.   regEx.IgnoreCase = False
  24.   retVal = regEx.Test(strng)
  25.   If retVal Then
  26.     RegExpTest = 1
  27.   Else
  28.     RegExpTest = 0
  29.   End If
  30. End Function
  31. Function GetHtml(PageCode,startstr,overstr)
  32.     Dim start,over
  33.     If InStr(PageCode,startstr) > 0 And InStr(PageCode,overstr) > 0 Then   
  34.     start=Instr(1,PageCode,startstr,vbBinaryCompare)+len(startstr)
  35.     over=Instr(start,PageCode,overstr,vbBinaryCompare)-start
  36.     GetHtml=Mid(PageCode,start,over)
  37.     Else
  38.     GetHtml =0
  39.     End If
  40. End Function
  41. Function BytesToBstr(body,Cset)
  42. dim objstream
  43. set objstream = Server.CreateObject("adodb.stream")
  44. objstream.Type = 1
  45. objstream.Mode =3
  46. objstream.Open
  47. objstream.Write body
  48. objstream.Position = 0
  49. objstream.Type = 2
  50. objstream.Charset = Cset
  51. BytesToBstr = objstream.ReadText
  52. objstream.Close
  53. set objstream = nothing
  54. End Function

  55. url="http://www.baidu.com"
  56. response.Write getHTTPPage(url)



  57. %>
复制代码

微信截图_20190820153940.png
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表

在线客服

售前咨询
售后咨询
服务热线
023-58418553
微信公众号