2014-01-24 60 views
0

我想下载这个网站无法下载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 ......或者是什么?

+0

需要更多信息。 “使用这个代码” - 为什么?那是什么语言?看起来像一些Javascript,但是再次..它不。 – MortenMoulder

+0

@Snorlax java和android见标签 – user36603

+0

是的,我明白了。它仍然没有意义。 “试图下载这个html”是什么意思? - 你想用Java显示它吗?您是否尝试使用Java下载并将其存储在SDCard上? – MortenMoulder

回答

3

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

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

通常它迫使浏览器的位置重新加载页面。我认为它实际上是你想要下载的页面“.... link ...?attempt = 1”。

如果你不使用脚本中定义的cookie,它不能确定它会工作,但它值得一试。

+0

WTF是这个网站! ;)它在浏览器中的位置? – Julien

+1

感谢您的好建议,我只是重新连接到Cookie BPC = f563534535121d5a1ba5bd1e153b – user36603