Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load a div into a webview on Android

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.

like image 565
maephisto Avatar asked Jul 04 '12 08:07

maephisto


1 Answers

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

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);
like image 122
alexgophermix Avatar answered Sep 20 '22 11:09

alexgophermix