vb.net如何访问WebBrowser中的iframe
这是以前vb6的方法,必须引用Microsoft html object library 可是在中没有作用了
单击command1获得框架及其元素方法1
Private Sub Command1_Click()
Dim Doc2 As HTMLDocument
Dim Web2 As WebBrowser_V1
Set Web2 = GetFrameIframeLikeUrl(WebBrowser1.Document, "*baidu.com*")
If Not Web2 Is Nothing Then
Set Doc2 = Web2.Document
'MsgBox "框架网页中的文字是:" & Doc2.body.innerText
End If
End Sub
方法一的自定义函数
Function GetFrameIframeLikeUrl(Vdoc As HTMLDocument, LikeUrl As String) As WebBrowser_V1
Dim Vtag, Tname As String, FrameWeb As WebBrowser_V1
For Each Vtag In Vdoc.All
Tname = Vtag.tagName
If Tname = "IFRAME" Or Tname = "FRAME" Then
Set FrameWeb = Vtag
If FrameWeb.LocationURL Like LikeUrl Then
Set GetFrameIframeLikeUrl = FrameWeb
Exit Function
End If
End If
Next
End Function