gpt4 book ai didi

java - 如何从 Webview 的页面内部获取 json 响应(我使用用户代理获取响应)?

转载 作者:行者123 更新时间:2023-12-01 16:30:01 25 4
gpt4 key购买 nike

Json i want to get is here, I want to keep this 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

最佳答案

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

关于java - 如何从 Webview 的页面内部获取 json 响应(我使用用户代理获取响应)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62067489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com