Jsoup无法从网页上获取完整内容[没有错误/异常,但是错过了一些内容] [英] Jsoup is unable to fetch complete content from a webpage[No errors/exceptions, but misses some content]
问题描述
我正在尝试使用JSOUP从以下页面获取内容:
I am trying to fetch content from following page with JSOUP:
http://www.exchangeandmart.co.uk/used-cars-for-sale
但是虽然当我从浏览器打开相同的链接时它是可见的,但它不会获取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.
推荐答案
文档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访问。
Now the page should be rendered as accessed from Chrome on PC.
这篇关于Jsoup无法从网页上获取完整内容[没有错误/异常,但是错过了一些内容]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!