0

In Android studio is there such thing as retrieving only a single element from a website and sending it to a webview?

Lets take https://accounts.google.com/ as an example. If I want to only display the "Create account" button, how can I delete all the elements except that create button with class "RveJvd snByac" and without having to manually do this: "document.getElementByClass('AnyOtherClass').style.display='none'; "?

Or is there a javascript command that can delete all elements but bring back this element with class name "RveJvd snByac"?

Here is what I have tried:

Element with id=yDmH0d is the html body. Element with class name=RveJvd snByac is the element I want to keep.

webView1.setWebViewClient(new WebViewClient() {

    @Override
    public void onPageFinished(WebView view, String url)
    {
        webView1.loadUrl("javascript:(function() { " +
                    "document.getElementById('yDmH0d')[0].style.display='none'; })()"+
                    "document.getElementsByClassName('RveJvd snByac')[0].style.display='block'; })()");

    }
});
webView1.loadUrl("https://accounts.google.com/");

1 Answers1

0

Actually you can use JSoup to load your elements selectively into webview.

Refer this, Load document to WebView with JSOUP

Saikrishna Rajaraman
  • 3,205
  • 2
  • 16
  • 29