简体   繁体   English

将WebBrowser控件内容保存为HTML

[英]Save WebBrowser Control Content to HTML

I have a WebBrowser Control and have called the Navigate(url) function of it for a given file. 我有一个WebBrowser控件,并为给定的文件调用它的Navigate(url)函数。 Then I have manipulated the DOM tree by giving new Id's to some of the tags. 然后我通过给一些标签提供新的Id来操纵DOM树。

Now I want to save the result in an HTML file. 现在我想将结果保存在HTML文件中。 I have tried to use the webBrowser.DocumentStream, but it seems that this stream won't change after manipulating the DOM tree. 我曾尝试使用webBrowser.DocumentStream,但似乎在操作DOM树后此流不会更改。

Please keep in mind that the encoding in WebBrowser.Document.Encoding must be used to encode the result. 请记住,必须使用WebBrowser.Document.Encoding中的编码来对结果进行编码。

像这样:

File.WriteAllText(path, browser.Document.Body.Parent.OuterHtml, Encoding.GetEncoding(browser.Document.Encoding));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM