Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jsoup is giving a different HTML document compared to my browser

I made sure to use my browser's User Agent, and it still gives a different HTML. I also tried using Jsoup.parse(Url, int) instead of Jsoup.connect(String). The two attempts:

Document doc = Jsoup.connect("https://www.bulq.com/lots/search/?category=Consumer%20Electronics&condition%5B%5D=Brand%20New")
.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.1Safari/605.1.15")
.get();

and

URL mainUrl = new URL("https://www.bulq.com/lots/search/category=Consumer%20Electronics&condition%5B%5D=Brand%20New");
Document doc = Jsoup.parse(mainUrl, 6000);

I'm using Safari's "Show Page Source" in the "Elements" tab. I tried to copy some HTML below but the formatting won't work :( so here's a tiny example.

Example: one of the div classes in Jsoup HTML is:

div class="row ng-cloak" ui-view

while the Safari HTML is:

div class="row ng-scope" ui-view
like image 877
NoClue Avatar asked Jan 27 '26 18:01

NoClue


1 Answers

I think you can try sending User-Agent as header with jsoup

Document doc = Jsoup.connect(url)
                    .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7")
                    .get();
like image 198
Zendy Avatar answered Jan 30 '26 10:01

Zendy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!