How to view source HTML from an InternetExplorer Object?

后端 未结 1 557
借酒劲吻你
借酒劲吻你 2021-01-16 03:26

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.

This is the code I\'m using:



        
相关标签:
1条回答
  • 2021-01-16 04:05

    Try that:

    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;
    

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

    string content = htmlDoc.body.parent.outerHTML;
    

    You can see a nice example here (the example in c++)

    0 讨论(0)
提交回复
热议问题