private void logData(WebView view, final String url) {
view.evaluateJavascript("document.documentElement.outerHTML.toString()", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Ion.with(context).load(url).asString().setCallback(new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result) {
if (result != null && result.length() > 0) {
int maxLogSize = 1000;
for (int i = 0; i <= result.length() / maxLogSize; i++) {
int start = i * maxLogSize;
int end = (i + 1) * maxLogSize;
end = Math.min(end, result.length());
Log.v("LoggedHTML", result.substring(start, end));
}
}
}
});
}
})
}
这段代码给我提供了页面的html文档,我想打印json。
WebViewClient yourWebClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
wb.loadUrl("javascript:HtmlViewer.showHTML" +
"('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
}
};
wb = (WebView) findViewById(R.id.webview);
wb.getSettings().setJavaScriptEnabled(true);
wb.getSettings().setSupportZoom(true);
wb.getSettings().setBuiltInZoomControls(true);
wb.setWebViewClient(yourWebClient);
wb.loadUrl("http://pqrs.abcde.com/facebook");
wb.addJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer");