开发者

Read HTML content of webview widgets

开发者 https://www.devze.com 2023-02-25 12:06 出处:网络
I want开发者_C百科 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?You can inject a javascript into webView and

I want开发者_C百科 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?


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

精彩评论

暂无评论...
验证码 换一张
取 消