WPF webbrowser - get HTML downloaded?
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.
Mathias Lykkegaard Lorenzen
Updated on June 05, 2022Comments
-
Mathias Lykkegaard Lorenzen almost 2 years
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 alwaysnull
.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.
-
Mathias Lykkegaard Lorenzen almost 7 yearsWhy on earth did they decide to go with the
dynamic
variable though? -
Alexandru Dicu almost 3 yearsThis code throws this exception for me: 'System.__ComObject' does not contain a definition for 'documentElement' Any thoughts ?