问题描述
我怎样才能获取框架的html源?
我可以通过WebBrowser1.DocumentText来回溯主框架
但是我想要追溯内部(孩子) )框架......
WebBrowser1.Document.Window.Frames(0).DocumentText之类的东西不存在......
How can I grab html source of a frame?
I can retrive main frame by WebBrowser1.DocumentText
but I want to retrive inner (child) frame...
WebBrowser1.Document.Window.Frames(0).DocumentText like thing doesn''t exist...
推荐答案
看看这是否有帮助:
Private LinksTable As Hashtable
Private Sub WebBrowser1_DocumentCompleted(ByVal _
sender As Object,ByVal e As _
System.Windows.Forms.WebBrowserDocumentCompletedEv entArgs)_
处理WebBrowser1.DocumentCompleted
GetLinksFromFrames()
结束子
Private Sub GetLinksFromFrames()
LinksTable = New Hashtable()
Dim FrameUrl As String
If(Not WebBrowser1.Document什么都没有)然后
使用WebBrowser1.Document
Dim CurrentWindow作为HtmlWi ndow = .Window
if(CurrentWindow.Frames.Count 0)然后
为每个帧作为HtmlWindow在_
Frame.Document.Links
FrameUrl = Frame.Url.ToString()
Dim ThisFrameName As String = Frame.Name
Dim ThisFrameDocument As _
HtmlDocument = Frame.Document
Dim FrameLinksHash As New Hashtable()
LinksTable.Add(FrameUrl,FrameLinksHash)
每个HrefElement作为HtmlElement在_
Frame.Document.Links
FrameLinksHash.Add(HrefElement.GetAttribute _
(HREF),Url)
下一页
下一页
否则
Dim DocLinksHash As New Hashtable()
LinksTable.Add(。Urr.ToString(),DocLinksHash)
每个HrefElement为HtmlElement In .Links
DocLinksHash.Add(HrefElement.GetAttribute _
(" HREF")," Url")
下一页
结束如果
结束
结束如果
End Sub
Gene
See if this helps:
Private LinksTable As Hashtable
Private Sub WebBrowser1_DocumentCompleted(ByVal _
sender As Object, ByVal e As _
System.Windows.Forms.WebBrowserDocumentCompletedEv entArgs) _
Handles WebBrowser1.DocumentCompleted
GetLinksFromFrames()
End Sub
Private Sub GetLinksFromFrames()
LinksTable = New Hashtable()
Dim FrameUrl As String
If (Not WebBrowser1.Document Is Nothing) Then
With WebBrowser1.Document
Dim CurrentWindow As HtmlWindow = .Window
If (CurrentWindow.Frames.Count 0) Then
For Each Frame As HtmlWindow In _
Frame.Document.Links
FrameUrl = Frame.Url.ToString()
Dim ThisFrameName As String = Frame.Name
Dim ThisFrameDocument As _
HtmlDocument = Frame.Document
Dim FrameLinksHash As New Hashtable()
LinksTable.Add(FrameUrl, FrameLinksHash)
For Each HrefElement As HtmlElement In _
Frame.Document.Links
FrameLinksHash.Add(HrefElement.GetAttribute _
("HREF"), "Url")
Next
Next
Else
Dim DocLinksHash As New Hashtable()
LinksTable.Add(.Url.ToString(), DocLinksHash)
For Each HrefElement As HtmlElement In .Links
DocLinksHash.Add(HrefElement.GetAttribute _
("HREF"), "Url")
Next
End If
End With
End If
End Sub
Gene
\\\
$ b每个帧的$ b为HtmlWindow在Me.WebBrowser1.Document.Window.Frames
MsgBox(Frame.Document.All(1).OuterHtml)
Next Frame
///
-
MS Herfried K. Wagner
MVP< URL:http ://dotnet.mvps.org/>
VB< URL:http://classicvb.org/petition/>
\\\
For Each Frame As HtmlWindow In Me.WebBrowser1.Document.Window.Frames
MsgBox(Frame.Document.All(1).OuterHtml)
Next Frame
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
这篇关于WebBrowser1.DocumentText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!