Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read HTML content of webview widgets

I want to read HTML content of webview widgets.

Is there any property or method which can be used to fetch the HTML of the currently open page?

like image 349
Android Avatar asked Jan 21 '23 00:01

Android


1 Answers

You can inject a javascript into webView and get the html element. Check below code...

class MyJavaScriptInterface {
    @SuppressWarnings("unused")
    @JavascriptInterface
    public void showHTML(final String html) {
        //HTML content of the page 
    }
}
mWebView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
mWebView.loadUrl("javascript:window.HTMLOUT.showHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
like image 111
Sukumar Avatar answered Feb 04 '23 02:02

Sukumar