Jsoup 无法从网页获取完整内容(没有错误/异常,但丢失了一些内容)

发布于 2024-12-15 09:47:17 字数 597 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光清浅 2024-12-22 09:47:17

文档 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文