数据加载到WebView不是同一个chrome mobile

时间:2017-01-08 10:26:38

标签: javascript android webview jsoup

我正在使用Jsoup来解析这个页面:

http://m.truyentranh8.net/yen-son-phai-va-bach-hoa-mon-chap-77

这是漫画手机网站的链接。因为链接图像是在一些JavaScript执行后生成的,所以我使用WebView伪造来获取字符串响应。这是伪造WebView的代码:

fakeWebView.getSettings().setJavaScriptEnabled(true);
fakeWebView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 5.0; SC-02F Build/LRX21V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.91 Mobile Safari/537.36");
fakeWebView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");

fakeWebView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
       // fakeWebView.loadUrl("javascript:(function(){document.body.innerHTML = document.body.innerHTML.replace('" + "option value=\"560\" selected"+"', '" + "option value=\"560\""+"')})()");
        //fakeWebView.loadUrl("javascript:(function(){document.body.innerHTML = document.body.innerHTML.replace('" + "option value=\"360\""+"', '" + "option value=\"360\"  selected"+"')})()");
        fakeWebView.loadUrl("javascript:HTMLOUT.processHTML(document.documentElement.outerHTML);");
    }
});
fakeWebView.loadUrl(chapter.tag);

,然后

class MyJavaScriptInterface {
    @JavascriptInterface
    @SuppressWarnings("unused")
    public void processHTML(String html) {
        new AsyncTask<String, Void, Chapter>() {
            @Override
            protected Chapter doInBackground(String... htmlToParse) {
                Document doc = Jsoup.parse(htmlToParse[0]);
                ......

                return chapter;
            }

            @Override
            protected void onPostExecute(Chapter chapter) {
                super.onPostExecute(chapter);
            }
        }.execute(html);
    }
}

除非在以下情况下使用手机时从WebView加载的图像不同,否则一切看起来都不错:

  • 来自webview :图片大小为1119×1600
  • 来自手机:小尺寸540×960
  • 的图片

然后图像加载速度非常慢。我尝试将user-agent更改为mobile

0 个答案:

没有答案