将WebBrowser控件内容保存到HTML [英] Save WebBrowser Control Content to HTML

查看:242
本文介绍了将WebBrowser控件内容保存到HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WebBrowser控件,并已为给定文件调用了它的Navigate(url)函数。然后,我通过为某些标记提供新的ID来操纵DOM树。

I have a WebBrowser Control and have called the Navigate(url) function of it for a given file. Then I have manipulated the DOM tree by giving new Id's to some of the tags.

现在,我想将结果保存到HTML文件中。我尝试使用webBrowser.DocumentStream,但在操作DOM树后,似乎该流不会改变。

Now I want to save the result in an HTML file. I have tried to use the webBrowser.DocumentStream, but it seems that this stream won't change after manipulating the DOM tree.

请记住,WebBrowser中的编码.Document.Encoding必须用于对结果进行编码。

Please keep in mind that the encoding in WebBrowser.Document.Encoding must be used to encode the result.

推荐答案

就像这样:

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

这篇关于将WebBrowser控件内容保存到HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆