与我的浏览器相比,Jsoup提供了不同的HTML文档 [英] Jsoup is giving a different HTML document compared to my browser

查看:63
本文介绍了与我的浏览器相比,Jsoup提供了不同的HTML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确保使用浏览器的用户代理,并且仍然提供不同的HTML.我还尝试使用Jsoup.parse(Url,int)而不是Jsoup.connect(String).两次尝试:

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

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

我在元素"选项卡中使用Safari的显示页面源".我试图在下面复制一些HTML,但是格式无法使用:(因此,这是一个小例子.

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.

示例:Jsoup HTML中的div类之一是:

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

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

Safari HTML为:

while the Safari HTML is:

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

推荐答案

我认为您可以尝试使用jsoup发送User-Agent作为标头

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

这篇关于与我的浏览器相比,Jsoup提供了不同的HTML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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