Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF webbrowser - get HTML downloaded?

I'm listening to the WPF webbrowser's LoadCompleted event. It has some navigation arguments which provide details regarding the navigation. However, e.Content is always null.

Am I paying attention to the wrong event here? How can I fetch the HTML that was just downloaded as string?

I tried some things which I would consider hacks, but they return a string of HTML, even though that was not the string downloaded. For instance, with that method when I go to a page which just sends me the string abc, I get the result <document><body>abc</body></document> or something similar.

I would prefer not getting into any more hacks than nescessary to get this running.

like image 607
Mathias Lykkegaard Lorenzen Avatar asked Apr 02 '12 17:04

Mathias Lykkegaard Lorenzen


Video Answer


1 Answers

This event will only be fired for top-level navigations, probably the reason of your initial problem.

The approach that you mentioned is not hacking at all, it is an official API returning HTML text (including all tags) of the downloaded document.

dynamic doc = webBrowser.Document;
var htmlText = doc.documentElement.InnerHtml;

If you want to get a plain text from your HTML document, there is a simple explanation how to do that.

like image 107
Flot2011 Avatar answered Sep 29 '22 09:09

Flot2011