当我的 WebBrowser 控件四处导航时,我编写了一个函数来保存站点源代码。我不能只保存 WebBrowser.DocumentText ,因为它会遗漏所有框架内容。
我现在遇到的问题是访问框架内容 - 我找不到包含它的方法/属性。
下面使用一个简单的 WebBrowser 控件,只需放入saveWebsite(FilePath, WebBrowser1)
DocumentCompleted 事件。
我在 VB.NET 中完成了这项工作,但对 C# 很熟悉,所以 C# 解决方案也不错
Public Sub saveWebsite(ByVal sDirectory As String, ByVal oBrowser As WebBrowser)
File.WriteAllText(sDirectory & "index.htm", oBrowser.DocumentText)
'Now write a file for each frame - putting each file in its relative path'
For Each oFrame As HtmlWindow In oBrowser.Document.Window.Frames
oFI = New FileInfo(sDirectory & oBrowser.Url.MakeRelativeUri(oFrame.Url).ToString)
oFI.Directory.Create()
'ISSUE: This is the issue, unlike with oBrowser, there is no DocumentText property for oFrame.'
'ISSUE: Ive tried several things like Body.InnerText/Html, Body.OuterText/HTML, etc.'
File.WriteAllText(oFI.ToString, oFrame.WindowFrameElement.InnerText )
Next oFrame
End Sub