vb如何获得webBrowser控件里选定对象的url

来源:百度知道 编辑:UC知道 时间:2024/06/02 16:52:53
就是这样的虚线框着的对象的url
最好写一个例子出来谢谢

Sub gourl(canshu1)

For i = 1 To WebBrowser1.Document.All.length - 1
If UCase(WebBrowser1.Document.All(i).tagName) = "A" Then
If InStr(WebBrowser1.Document.All(i).innertext, "下一页") Then
msgbox WebBrowser1.Document.All(i).href

end if

End If
Next i

End Sub

读懂就能看懂。。
遍历,看看有没有下一页这几个字
未经调试,正确率98%

Private Sub Command1_Click()
WebBrowser1.Navigate "www.baidu.com"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim x As Long

For x = 0 To WebBrowser1.Document.links.length - 1
Debug.Print WebBrowser1.Document.links.Item(x)
Next x
Debug.Print "共有" & WebBrowser1.Document.links.length & "个链接。"
End Sub

WebBrowser1.Document.activeElement.href