Web Browser control getting the document downloaded

  • Thread starter Thread starter Muscha
  • Start date Start date
M

Muscha

Hi,

Is there a way to get the current content of the web browser control? As in
the browser is the "View Source" functionality?

thanks.

/m
 
Yeah, this is a pretty simple process.

You use the WebBrowser's document property to get the actual the HTML
document into an IHTMLDocument2 interface.

So it'll be something like this:
IHTMLDocument2 idoc = wb.document;

Then with the interface, you can get access to the body HTML using

string source = idoc.body.innerHTML;

But as i re-read your post, I notice the above solution only gives the
<body> HTML as opposed to the entire source. I've never really had to
do that before, but the above will give a start on what you'll need to
do. I imagine it's not much more difficult.
 
If all you want is to get a string that contains the entire HTML
document, you can do:

string html = ((IHTMLDocument3)webBrowser.Document).documentElement.outerHTML;
 
Back
Top