从嵌入在 C# 中的浏览器控件获取 HTML 源代码 [英] Get HTML source code from browser control embedded in C#

查看:42
本文介绍了从嵌入在 C# 中的浏览器控件获取 HTML 源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C# windows 应用程序中嵌入了一个浏览器控件.我想获取呈现的 HTML(可能已被 javascript 修改)而不是原始 HTML.

I have a browser control embeded in a C# windows app. I want to grab the rendered HTML (which could have been modified by javascript) not the original one.

有什么建议吗?

推荐答案

您可以使用 WebBrowser.DocumentText.

Sheng 是正确的,DocumentText 在脚本运行之前返回流式文档.他的代码无法编译,但本质上是正确的.我发现你需要:

Sheng is correct, DocumentText returns the streamed document before scripts run. His code doesn't compile, but it's essentially correct. I found that you need:

mshtml.HTMLDocument doc = webBrowser1.Document.DomDocument as mshtml.HTMLDocument;
string html = doc.documentElement.outerHTML;

这篇关于从嵌入在 C# 中的浏览器控件获取 HTML 源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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