如何从InternetExplorer对象查看源HTML?
当我实例化IE对象并导航到URL时,我不知道如何从该地址获取源HTML代码。
这是我正在使用的代码:
SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer(); IE.Visible = false; IE.Navigate("www.testsite.com");
我想要的东西:
string source = IE.ToSource();
所以我可以检查一下它的内容。 我能做到吗? 谢谢。
试试看:
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字符串:
string content = htmlDoc.body.parent.outerHTML;
你可以在这里看到一个很好的例子(c ++中的例子)