加载一个div到Android上的WebView [英] Load a div into a webview on Android

查看:221
本文介绍了加载一个div到Android上的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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);

这篇关于加载一个div到Android上的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆