为什么我的 JSoup 请求 return 一个空文档?
Why does my JSoup request return an empty document?
我想抓取网站的内容,但它似乎不起作用:
public static void main(String[] args) throws Exception {
String url = "https://www.rl-trades.com";
Document doc = Jsoup.connect(url).userAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36").get();
System.out.println(doc);
}
我得到的是这个:
<html>
<head></head>
<body></body>
</html>
问题似乎出在网站上,因为在其他网站上提出的每个类似问题都对我有用。我也尝试了这个更高级的版本,但我得到了完全相同的结果:
public static void main(String[] args) throws Exception {
String url = "https://www.rl-trades.com";
Response response= Jsoup.connect(url)
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.referrer("http://www.google.com")
.timeout(12000)
.followRedirects(true)
.execute();
Document doc = response.parse();
System.out.println(doc);
}
还有什么方法可以获取内容吗?还是网站上只有抓取保护而没有解决方法?
提前致谢!
看起来这个网站喜欢 Accept-Language header:
String url = "https://www.rl-trades.com";
Connection connection = Jsoup.connect(url);
connection.header("Accept-Language","en");
Document doc = connection.get();
System.out.println(doc);
我想抓取网站的内容,但它似乎不起作用:
public static void main(String[] args) throws Exception {
String url = "https://www.rl-trades.com";
Document doc = Jsoup.connect(url).userAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36").get();
System.out.println(doc);
}
我得到的是这个:
<html>
<head></head>
<body></body>
</html>
问题似乎出在网站上,因为在其他网站上提出的每个类似问题都对我有用。我也尝试了这个更高级的版本,但我得到了完全相同的结果:
public static void main(String[] args) throws Exception {
String url = "https://www.rl-trades.com";
Response response= Jsoup.connect(url)
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.referrer("http://www.google.com")
.timeout(12000)
.followRedirects(true)
.execute();
Document doc = response.parse();
System.out.println(doc);
}
还有什么方法可以获取内容吗?还是网站上只有抓取保护而没有解决方法?
提前致谢!
看起来这个网站喜欢 Accept-Language header:
String url = "https://www.rl-trades.com";
Connection connection = Jsoup.connect(url);
connection.header("Accept-Language","en");
Document doc = connection.get();
System.out.println(doc);