如何从Webview中获取页面内部的json响应(我得到的是user-agent的响应)?

问题描述 投票:0回答:1

我想得到的Json在这里,我想保留这个Json。

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。

java android android-webview instagram-api user-agent
1个回答
0
投票
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");
© www.soinside.com 2019 - 2024. All rights reserved.