【问题标题】:Can't download html无法下载html
【发布时间】:2014-01-24 09:49:22
【问题描述】:

我正在尝试下载此 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...或什么?

【问题讨论】:

  • 需要更多信息。 “使用此代码” - 为了什么?那是什么语言?看起来像一些 Javascript,但话又说回来......它没有。
  • @Snorlax java 和 android 查看标签
  • 是的,我明白了。它仍然没有意义。 “尝试下载此 html”是什么意思 - 您是否尝试使用 Java 显示它?您是否尝试使用 Java 将其下载并存储在 SDCard 上?
  • @Snorlax 将本页的资源下载到字符串

标签: java android html download jsoup


【解决方案1】:

在脚本标签中,你有这样的语句:

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

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

如果您不使用脚本中定义的 cookie,不确定它是否会起作用,但值得一试。

【讨论】:

  • WTF就是这个网站! ;) 它在浏览器中的什么位置?
  • 感谢您的好建议,我刚刚重新连接以链接 cookie BPC=f563534535121d5a1ba5bd1e153b
猜你喜欢
  • 1970-01-01
  • 2018-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多