问题
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,
回答1:
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.
来源:https://stackoverflow.com/questions/27948238/retrieve-inner-text-from-webview-html-in-windows-windows-phone-8-1