nos9
nos9

Reputation: 631

Retrieve Inner Text from WebView HTML in Windows/Windows Phone 8.1

I'm creating a universal app and need to be able to pull plain text from a HTML page. I know that in WPF you can utilize the IHTMLDocument2 interface to achieve this.

IHTMLDocument2 document = webBrowser1.Document as IHTMLDocument2;
string data = document.body.innerText;

Is there something similar for Windows Runtime?

Thanks,

Upvotes: 0

Views: 1019

Answers (1)

Jon G Stødle
Jon G Stødle

Reputation: 3904

I would use something like HtmlAgilityPack. The HTML then becomes queryable through Linq. Then you can do something like this:

HtmlDocument htmlDoc = webBrowser1.Document as HtmlDocument;
string innerText = htmlDoc.DocumentNode.Descendants("body").Single().InnerText;

You can also load the HTML as a string or stream through LoadHtml and Load respectively.

Upvotes: 1

Related Questions