加载一个div到Android上的WebView加载、div、WebView、Android

2023-09-13 00:46:41 作者:空城,独留我一人

我有一个Android应用程序,至极含有的WebView,我想它不是一个网页显示,但从该网页只是一个div。我要指出,我没有访问该页面。

I have an android app, wich contains a WebView, and I would like to display in it not a webpage, but only a div from that webpage. I should mention that I do not have access to that page.

感谢您!

推荐答案

我会建议 Jsoup 。它比tagsoup大,但提供了内置的功能从URL拉HTML和是超级好用。例如,如果你想拉一个 DIV id为例如你会做到以下几点:

I would recommend Jsoup. It's larger than tagsoup but provides inbuilt functionality to pull the HTML from the URL and is super easy to use. For example if you want to pull a div with id example you would do the following:

Document doc = Jsoup.connect(url).get();
Elements ele = doc.select("div#example");

然后加载你已经提取到Web视图中的HTML,你会怎么做:

Then to load the HTML you've extracted into your web view you would do:

String html = ele.toString();
String mime = "text/html";
String encoding = "utf-8";
webView.loadData(html, mime, encoding);