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

▼魔方 西西 提交于 2019-12-24 23:25:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!