Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView loading part of a website

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?

like image 712
aandroidtest Avatar asked Nov 01 '22 07:11

aandroidtest


1 Answers

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);
like image 68
Joy Hard Avatar answered Nov 11 '22 11:11

Joy Hard