Read HTML content of webview widgets

蹲街弑〆低调 提交于 2019-12-29 07:08:38

问题


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:


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


来源:https://stackoverflow.com/questions/5672958/read-html-content-of-webview-widgets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!