如何从InternetExplorer对象查看源代码的HTML? [英] How to view source HTML from an InternetExplorer Object?

查看:667
本文介绍了如何从InternetExplorer对象查看源代码的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我实例化一个IE浏览器对象并导航到一个网址,我不知道如何获得该地址的HTML源$ C ​​$ C。

When I instantiate an IE object and navigate to a url, I don't know how to obtain the source HTML code from that address.

这是在code我使用:

This is the code I'm using:

SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
IE.Visible = false;
IE.Navigate("www.testsite.com");

我想是这样的:

I want something like:

string source = IE.ToSource();

所以,我可以检查它的内容。 我能做到这一点?谢谢你。

So I can inspect the content of it. Can I achieve this? Thanks.

推荐答案

试试:

SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
IE.Visible = false;
IE.Navigate("www.testsite.com");
mshtml.IHTMLDocument2 htmlDoc 
         = IE.Document as mshtml.IHTMLDocument2;
string content = htmlDoc.body.outerHTML;

您可以从body.parent属性来访问整个HTML字符串:

You can access the whole HTML string from the body.parent property:

string content = htmlDoc.body.parent.outerHTML;

你可以看到一个很好的例子这里(++的例子C)

这篇关于如何从InternetExplorer对象查看源代码的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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