[正则获取网页的超链接]正则获取网页的超链接和链接文本(a href),适用于asp vb vbscipt

更新时间:2019-11-29 来源:模拟经营 点击:

【www.hzclsc.cn--模拟经营】

 

以vb6为例,获取给定的网址的外链的链接地址和链接文本,这里过滤了网站本身的网址,还有一些客服代码
也可以以常见的搜索引擎蜘蛛模拟访问
VB6需要引用 :在“项目”菜单上单击“引用“Microsoft VBScript Regular Expressions 5.5


Public Function HtmlGetLinks(url, zhizu) " 从网址内获取外链地址 参数:网址,蜘蛛类型
  "On Error Resume Next
  Dim str, reg, objMatches, key1
  url2 = Replace(url, "http://", "")
  url = "http://" url2
  str = GetUrlHtmlUTF(url, "auto", zhizu)
  Set reg = New RegExp
  reg.IgnoreCase = True
  reg.Global = True
  reg.Pattern = "href=[\""\"\s]?http://([^\s]+)(.*?)\b[\""\"\s]?(.*?) (.*?) /a "
  Set objMatches = reg.Execute(str)
  If objMatches.Count 0 Then
  For i = 0 To objMatches.Count - 1
  url1 = objMatches(i).SubMatches(0)
  url1 = Replace(url1, """", "")
  url1 = Replace(url1, """, "")
  Keyword = objMatches(i).SubMatches(3)
  Keyword = LCase(Keyword)
  Keyword = Replace(Keyword, """, """")
  If InStr(Keyword, "src") 0 Then
  Keyword = FindStrMulti(Keyword, "src=""", """", "")
  Keyword = "图片:" Keyword
  Else
  Keyword = RemoveHTML(Keyword)
  End If
  If InStr(url1, url2) = 0 And InStr(Keyword, "wpa.qq.com") = 0 And InStr(url1, "51.la") = 0 And InStr(url1, "cnzz.com") = 0 And InStr(url1, "taobao.com") = 0 And InStr(url1, "beian.gov.cn") = 0 Then
  key1 = key1 (Keyword "|" url1) vbCrLf
  End If
  DoEvents
  Next
  End If
  HtmlGetLinks = key1
End Function

 

Public Function GetUrlHtmlUTF(url, CodeBase, zhizu)
  Dim xmlHTTP1, GetCode, GetCode1
  Set xmlHTTP1 = CreateObject("Microsoft.XMLHTTP")
  xmlHTTP1.Open "get", url, True
  If zhizu "" Then
  Select Case zhizu
  Case "baidu"
  xmlHTTP1.setRequestHeader "UserAgent:", "Baiduspider+(+http://www.baidu.com/search/spider.htm)"
  Case "google"
  xmlHTTP1.setRequestHeader "UserAgent:", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
  Case "yahoo"
  xmlHTTP1.setRequestHeader "UserAgent:", "Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)"
  Case "yahoo"
  xmlHTTP1.setRequestHeader "UserAgent:", "Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)"
  Case "youdao"
  xmlHTTP1.setRequestHeader "UserAgent:", "Mozilla/5.0 (compatible; YodaoBot/1.0; http://www.yodao.com/help/webmaster/spider/; )"
  Case "soso"
  xmlHTTP1.setRequestHeader "UserAgent:", "Sosospider+(+http://help.soso.com/webspider.htm)"
  Case "sogou"
  xmlHTTP1.setRequestHeader "UserAgent:", "Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)"
  End Select
  End If
  xmlHTTP1.send
  While xmlHTTP1.ReadyState 4
  DoEvents
  Wend
  GetCode = xmlHTTP1.ResponseBody
  If CodeBase = "auto" Then
  GetCode1 = StrConv(Left(GetCode, 500), vbUnicode)
  If InStr(GetCode1, "charset=gb2312") 0 Then
  GetCode = StrConv(GetCode, vbUnicode)
  Else
  If CStr(GetCode) "" Then GetCode = BytesToBstr(GetCode, "UTF-8")
  End If
  Else
  If CStr(GetCode) "" Then GetCode = BytesToBstr(GetCode, CodeBase)
  End If
 
  GetUrlHtmlUTF = GetCode
  Set ObjXML = Nothing
End Function

本文来源:http://www.hzclsc.cn/danjiyouxi/41782.html

为您推荐

【茂伸奇谈happy end】茂伸奇谈常见问题及解决方法

茂伸奇谈(茂伸奇谈-Monobeno-)日前已经发售,那么许多玩家在游戏中遇到的一些问题该怎么解决呢?下面就来分享一下茂伸奇谈常见问题及解决方法。茂伸奇谈常见问题及解决方法《茂伸奇谈-Monobeno模拟游戏

2021-02-25 18:54:41  

【欧洲卡车模拟2方向盘设置】欧洲卡车模拟2方向盘180度设置教程 欧洲卡车模拟2方向盘180度怎么设置

您的位置:首页 → 单机游戏 → 模拟游戏 → 欧洲卡车模拟2方向盘180度设置教程 欧洲卡车模拟2方向盘180度怎么设置 欧洲卡车模拟2方向盘180度设置教程 欧洲卡车模拟2方向盘180度怎么设置时模拟游戏

2021-02-25 18:54:41  

欧洲卡车模拟2配置要求|欧洲卡车模拟2低配置画面设置优化方法 欧洲卡车模拟2画面怎么设置

您的位置:首页 → 单机游戏 → 模拟游戏 → 欧洲卡车模拟2低配置画面设置优化方法 欧洲卡车模拟2画面怎么设置 欧洲卡车模拟2低配置画面设置优化方法 欧洲卡车模拟2画面怎么设置时间:2018 2 2模拟游戏

2020-12-20 11:05:28  

【深海迷航秘籍代码】深海迷航秘籍怎么用 深海迷航秘籍代码大全

深海迷航秘籍怎么用?深海迷航游戏中使用秘籍可以快速的完成任务,增加物品收益,本文带来了秘籍代码及使用方法,有需要的玩家欢迎收藏。下面就一起来看看深海迷航秘籍代码大全吧。f3 f8同时打开,勾选掉禁用控模拟游戏

2020-12-20 07:04:16  

夏色祭|夏色心跳日志PSV版发售日期一览 夏色心跳日志PSV版什么时候出

夏色心跳日志(ナツイロココロログ)是一款著名的恋爱模拟游戏,日前即将登录PSV平台,下面就来分享一下夏色心跳日志PSV版发售日期。夏色心跳日志PSV版发售日期一览dramatic create社今天宣

2020-12-19 11:04:43   夏色奇迹   夏色祭中之人