如何在 Web 视图中显示包含图像的特定 div。

huangapple go评论62阅读模式
英文:

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,
如何在 Web 视图中显示包含图像的特定 div。
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!

huangapple
  • 本文由 发表于 2020年9月24日 13:52:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64040274.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定