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/"); 
2
  • There is no such thing as getElementsById. And you have syntax errors. Commented Jun 14, 2018 at 6:29
  • My bad. It should be document.getElementById() Commented Jun 14, 2018 at 6:31

1 Answer 1

0

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

Refer this, Load document to WebView with JSOUP

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.