Jsoup无法从网页中获取完整的内容(没有错误/异常,但是缺少了一些内容) [英] Jsoup is unable to fetch complete content from a webpage (No errors/exceptions, but misses some content)

查看:116
本文介绍了Jsoup无法从网页中获取完整的内容(没有错误/异常,但是缺少了一些内容)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JSOUP从下一页中获取内容:

I am trying to fetch content from following page with JSOUP:

http://www.exchangeandmart.co.uk/used-cars待售

但是,即使当我从浏览器中打开相同的链接时,它是可见的,它也不会使用id = results来获取div.请帮助我

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代码:

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);在控制台上打印了整个文档,这与我在浏览器中查看的页面完全不同.

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.

推荐答案

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();

现在应该将页面呈现为可从PC上的Chrome访问.

Now the page should be rendered as accessed from Chrome on PC.

这篇关于Jsoup无法从网页中获取完整的内容(没有错误/异常,但是缺少了一些内容)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆