无法下载HTML

时间:2014-01-24 09:49:22

标签: java android html download jsoup

我正在尝试下载此html

我正在使用此代码:

           Document doc = null;
        try {
            doc =Jsoup.connect(link).userAgent("Mozilla").get();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
Log.i ("html", doc.toString());

更新: ASLO试图使用它:

HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(link);
        HttpResponse response = null;
        try {
            response = client.execute(request);
        } catch (ClientProtocolException e1) {
            // 
            e1.printStackTrace();
        } catch (IOException e1) {
            // 
            e1.printStackTrace();
        }


        InputStream in = null;
        try {
            in = response.getEntity().getContent();
        } catch (IllegalStateException e1) {
            // 
            e1.printStackTrace();
        } catch (IOException e1) {
            // 
            e1.printStackTrace();
        }
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // 
            e.printStackTrace();
        }
        StringBuilder str = new StringBuilder();
        String line = null;
        try {
            while((line = reader.readLine()) != null)
            {
                str.append(line);
            }
        } catch (IOException e1) {
            // 
            e1.printStackTrace();
        }
        try {
            in.close();
        } catch (IOException e1) {
            // 
            e1.printStackTrace();
        }
        String html = str.toString();
        Log.e("html", html);

再次像这样回答:

         <html>
<body>
<script>document.cookie="BPC=f563534535121d5a1ba5bd1e153b";
    document.location.href="http://...link.../all?attempt=1";</script>
</body>
</html>

我找不到任何解决方案...无法下载页面可能因为没有cookie ......或者什么?

1 个答案:

答案 0 :(得分:3)

在脚本标记中,您有以下声明:

document.location.href="....link..../all?attempt=1";

通常会强制浏览器重新加载包含该位置的页面。我认为这是你想要下载的页面“.... link ...?attempt = 1”。

如果您不使用脚本中定义的cookie但是它值得一试,那么它无论如何都无法正常工作。