Reputation: 1503
Some websites have comments portion and many other unnecessary portions. I want to just display the main article excluding the other portions in my custom Android WebView
.
I have tried the example from Display a part of the webpage on the webview android
But it still shows the full website.
There is also the loaddatawithbaseurl
class in Android but it is not working too as you can't specify till which portion of a website to show using this class.
Is there any other way to do this?
Upvotes: 5
Views: 1206
Reputation: 319
Here it is with some changes...
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
String javaScript = "javascript: var form = document.getElementsByClassName('university_corner');"
+ "var body = document.getElementsByTagName('div');"
+ "body[0].innerHTML = form[0].innerHTML";
webView.loadUrl(javaScript);
}
});
webView.loadUrl(url);
Upvotes: 2