【发布时间】:2013-12-02 10:26:41
【问题描述】:
所以我正在尝试从 URL 下载 html 页面;
public static void getHtml(){
URL url;
InputStream is = null;
BufferedReader br;
String line;
try {
url = new URL(URL);
is = url.openStream();
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}catch(Exception e){
} finally {
try {
if (is != null) is.close();
} catch (IOException ioe) {
}
}
}
问题是,它给我的不是我想要的 HTML,而是以下内容:
<html>
<head>
<title>loading</title>
</head>
<body>
<p>Please wait...</p>
<script>document.cookie="a=3c5hb1488cb3eghv3r456t12234jfyr7g;path=/;";location.href=document.location.pathname;</script>
</body>
</html>
如何直接下载网页内容?我也尝试了 jsoup 但它给出了相同的结果。也试过 Apache - 一样。
【问题讨论】:
-
我知道这不是一个答案,但是您必须使用 java 下载网页吗?还有比这更简单的方法
-
首先尝试不同的网页以确认它不是特定于页面的
-
@Domecraft 我需要解析 html 以获取 js func,所以是的,我必须下载它
-
@ghostbust555 我确定它是特定于页面的。几天前它工作正常,我猜他们在那里改变了smth,但我仍然能够用我的浏览器查看源代码。有没有办法以编程方式做到这一点?