Jsoup 无法从网页获取完整内容(没有错误/异常,但丢失了一些内容)
我正在尝试使用 JSOUP 从以下页面获取内容:
http://www. Exchangeandmart.co.uk/used-cars-for-sale
但它不会获取 id=results 的 div,即使当我从浏览器打开相同的链接时它是可见的。请帮助我
Java 代码:
Connection connection = Jsoup.connect("http://www.exchangeandmart.co.uk/used-cars-for-sale");
Document doc = connection.get();
System.out.println(doc.getElementById("results")); // prints null
注意: 下载页面时没有异常或错误。仅缺少页面中的部分内容。我使用 System.out.println(doc); 在控制台上打印了整个文档,它与我在浏览器中查看的页面有很大不同。
I am trying to fetch content from following page with JSOUP:
http://www.exchangeandmart.co.uk/used-cars-for-sale
But it does not fetch the div with id=results, even though it is visible when I open the same link from the browser. Please help me
Java code:
Connection connection = Jsoup.connect("http://www.exchangeandmart.co.uk/used-cars-for-sale");
Document doc = connection.get();
System.out.println(doc.getElementById("results")); // prints null
NOTE: There are no exceptions or errors while downloading the page. Only some of the content in the page is missing. I printed the whole document on console with System.out.println(doc);
, it was quite different from the page I view in the browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档 doc = Jsoup.connect("http://www.exchangeandmart.co.uk/used-cars-for-sale").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 ( KHTML,如 Gecko) Chrome/15.0.874.120 Safari/535.2").get()
;现在,该页面应该呈现为从 PC 上的 Chrome 访问。
Document doc = Jsoup.connect("http://www.exchangeandmart.co.uk/used-cars-for-sale").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2").get()
;Now the page should be rendered as accessed from Chrome on PC.