将 div 加载到 Android 上的 webview 中 [英] Load a div into a webview on Android

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

问题描述

我有一个 Android 应用,其中包含一个 WebView,我想在其中显示不是网页,而是该网页中的 div.我应该提一下,我无权访问该页面.

I have an Android app, which 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 的内置功能,并且非常易于使用.例如,如果您想拉取一个带有 id examplediv,您可以执行以下操作:

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");

然后将您提取的 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天全站免登陆