Read HTML content of webview widgets

I want to read the HTML content of webview widgets.

Is there any property or method that can be used to extract the HTML of the current open page?

+4
source share
1 answer

You can embed javascript in your webView and get the html element. Check out the code below ...

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>');"); 
+8
source

All Articles