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

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

How to display specific div that have image in webview

问题

  1. I've got the following
  2. 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();
  3. Elements divs = doc.select("div");
  4. webViewAds.getSettings().setJavaScriptEnabled(true);
  5. for (Element div : divs) {
  6. String html = div.getElementsByClass("majalahpro-core-banner-insidecontent").toString();
  7. String mime = "text/html";
  8. String encoding = "utf-8";
  9. webView.loadData(html, mime, encoding);
  10. }
  11. i want to display this content on my webview,
  12. [![enter image description here][1]][1]
  13. but that's code doesn't work.
  14. pls help me
英文:

I've got the following

  1. 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();
  2. Elements divs = doc.select("div");
  3. webViewAds.getSettings().setJavaScriptEnabled(true);
  4. for (Element div : divs) {
  5. String html = div.getElementsByClass("majalahpro-core-banner-insidecontent").toString();
  6. String mime = "text/html";
  7. String encoding = "utf-8";
  8. webView.loadData(html, mime, encoding);
  9. }

i want to display this content on my webview,
如何在 Web 视图中显示包含图像的特定 div。
but that's code doesn't work.
pls help me

答案1

得分: 1

使用这段代码:

  1. // 获取所有具有你指定的类名的 div
  2. Elements links = doc.select("div.majalahpro-core-banner-insidecontent");
  3. // 遍历它
  4. for (Element link : links) {
  5. // 获取它的 HTML
  6. String content = link.html();
  7. }

享受吧!

英文:

Use this piece of code:

  1. // Get all divs with classname you specified
  2. Elements links = doc.select("div.majalahpro-core-banner-insidecontent");
  3. //Loop over it
  4. for (Element link : links) {
  5. // Get its Html
  6. String content = link.html();
  7. }

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:

确定