how to get html content from a webview?

后端 未结 12 1547
鱼传尺愫
鱼传尺愫 2020-11-22 04:29

Which is the simplest method to get html code from a webview? I have tried several methods from stackoverflow and google, but can\'t find an exact method. Please mention an

12条回答
  •  渐次进展
    2020-11-22 05:03

    In KitKat and above, you could use evaluateJavascript method on webview

    wvbrowser.evaluateJavascript(
            "(function() { return (''+document.getElementsByTagName('html')[0].innerHTML+''); })();",
             new ValueCallback() {
                @Override
                public void onReceiveValue(String html) {
                    Log.d("HTML", html); 
                    // code here
                }
        });
    

    See this answer for more examples

提交回复
热议问题