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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With