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
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 ;)
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
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
Try using DocumentText or DocumentStream properties.
have you tried WebBrowser1.DocumentText