VB求网页链接

来源:百度知道 编辑:UC知道 时间:2024/06/17 07:33:08
Option Explicit
Dim allCol
Dim TagName As String
Dim allcount, i

List1.Clear
Set allCol = WebBrowser1.Document.All
allcount = allCol.length
For i = 0 To allcount - 1
TagName = allCol.Item(i).TagName
If TagName = "A" Then
TagName = allCol.Item(i).href
List1.AddItem (TagName)
Open "E:\backup\桌面\网址\1.txt" For Append As #1

Write #1, TagName
Close #1
End If
Next
假如我的WebBrowser1源代码包含如下网址"http://zhidao.baidu.com/13112/default.html
http://zhidao.baidu.com/13222/default.html
http://zhidao.baidu.com/1323

Option Explicit
Dim allCol
Dim TagName As String
Dim allcount, i

Private Sub Form_Load()
WebBrowser1.Navigate "
http://zhidao.baidu.com/XXX/default.html" '请修改为具体的网址
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Open "E:\backup\桌面\网址\1.txt" For Append As #1
List1.Clear
Set allCol = WebBrowser1.Document.links
allcount = allCol.Length
For i = 0 To allcount - 1
TagName = allCol.Item(i).href
List1.AddItem TagName
Print #1, TagName
Next
Close #1
End Sub

先写在text里面然后再保存```

1