VB大神帮我写一个能够提取网页中所有的连接的程序
1个回答
展开全部
'引用
' Microsoft XML, v6.0
' Microsoft VBScript Regular Expressions 5.5
'控件:
'list1,Command1
Private Sub Command1_Click()
Dim xmlHttp As New xmlHttp
With xmlHttp
Dim url As String
url = InputBox("输入一个网址:", , "http://zhidao.baidu.com/")
.Open "GET", url, True
.send
While .readyState <> 4
DoEvents
Wend
If .Status = 200 Then ' xmlHttp.statusText, xmlHttp.Status '"OK" ,200
Dim htmlText As String
htmlText = .responseText
Dim RgExp As New RegExp
RgExp.Global = True
RgExp.IgnoreCase = True
RgExp.Pattern = "<a .*? href=""(.+?)"".*?>"
Dim Mc As MatchCollection
Set Mc = RgExp.Execute(htmlText)
Dim arUrl() As String
ReDim arUrl(Mc.Count - 1)
Dim Index As Integer: Index = -1
Dim Mh As Match
If url Like "*/" Then url = Left(url, Len(url) - 1)
For Each Mh In Mc
Index = Index + 1
arUrl(Index) = Mh.SubMatches(0)
If arUrl(Index) Like "/*" Then
arUrl(Index) = url & arUrl(Index)
End If
Next
arUrl = Filter(arUrl, "http://", True, vbTextCompare)
Dim item
For Each item In arUrl
List1.AddItem item
Next
End If
End With
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询