英文:
How to display specific div that have image in webview
问题
I've got the following
Document doc = Jsoup.connect("https://fajarpapua.com/2020/09/23/hasil-rapat-mulai-senin-aktifitas-warga-mimika-sampai-pukul-21-00-wit-ini-draft-aturan-baru-yang-wajib-dipatuhi/").get();
Elements divs = doc.select("div");
webViewAds.getSettings().setJavaScriptEnabled(true);
for (Element div : divs) {
String html = div.getElementsByClass("majalahpro-core-banner-insidecontent").toString();
String mime = "text/html";
String encoding = "utf-8";
webView.loadData(html, mime, encoding);
}
i want to display this content on my webview,
[![enter image description here][1]][1]
but that's code doesn't work.
pls help me
英文:
I've got the following
Document doc = Jsoup.connect("https://fajarpapua.com/2020/09/23/hasil-rapat-mulai-senin-aktifitas-warga-mimika-sampai-pukul-21-00-wit-ini-draft-aturan-baru-yang-wajib-dipatuhi/").get();
Elements divs = doc.select("div");
webViewAds.getSettings().setJavaScriptEnabled(true);
for (Element div : divs) {
String html = div.getElementsByClass("majalahpro-core-banner-insidecontent").toString();
String mime = "text/html";
String encoding = "utf-8";
webView.loadData(html, mime, encoding);
}
i want to display this content on my webview,
but that's code doesn't work.
pls help me
答案1
得分: 1
使用这段代码:
// 获取所有具有你指定的类名的 div
Elements links = doc.select("div.majalahpro-core-banner-insidecontent");
// 遍历它
for (Element link : links) {
// 获取它的 HTML
String content = link.html();
}
享受吧!
英文:
Use this piece of code:
// Get all divs with classname you specified
Elements links = doc.select("div.majalahpro-core-banner-insidecontent");
//Loop over it
for (Element link : links) {
// Get its Html
String content = link.html();
}
Enjoy!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论