Read HTML content of webview widgets

后端 未结 1 1134
遇见更好的自我
遇见更好的自我 2020-12-18 08:45

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?

相关标签:
1条回答
  • 2020-12-18 09:45

    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>');");
    
    0 讨论(0)
提交回复
热议问题