Getting the HTML source through the WebBrowser control in C#

前端 未结 5 667
一生所求
一生所求 2021-01-02 02:40

I tried to get HTML Source in the following way:

webBrowser1.Document.Body.OuterHtml;

but it does not work. For example, if the original HT

相关标签:
5条回答
  • 2021-01-02 02:59

    If you want to grab the entire HTML source of the WebBrowser control then use this - WebBrowser1.Document.GetElementsByTagName("HTML").Item(0).OuterHtml. This of course assumes you have properly formatted HTML and the HTML tag exists. If you want to narrow it down to just the body then obviously change the HTML tag to the BODY tag. This way you grab any and all changes after "DocumentText" has been set. Sorry, I'm a VB guy, convert as needed ;)

    0 讨论(0)
  • 2021-01-02 03:06

    Have a look at this. WebBrowser on MSDN

    Alternative you could use Webclient.DownloadString from System.Net (it also has WebClient.DownloadStringAsync...) Here is the description: WebClient on MSDN

    0 讨论(0)
  • 2021-01-02 03:08

    Thank you all. My final solution is: first,using body.outlineHtml to get html source. because body.outlineHtml may miss end-tag for <li> and <td>, so the second step is using tidy to repair the HTML source. after these, we can get the HTML source without error

    0 讨论(0)
  • 2021-01-02 03:10

    Try using DocumentText or DocumentStream properties.

    0 讨论(0)
  • 2021-01-02 03:18

    have you tried WebBrowser1.DocumentText

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