开发者

Mask jsoup as a Browser when downloading html

开发者 https://www.devze.com 2023-03-26 03:29 出处:网络
is it possible to mask Jsoup.connect(\"http://xyz.com\").get().html(); as a browser call to the website?

is it possible to mask

Jsoup.connect("http://xyz.com").get().html();

as a browser call to the website?

I try to build a wallpaper download tool and experiencing problems when downloading the page form the server.

If I downlo开发者_运维问答ad the page, say with Firefox, uploading this to a server of mine it is downloaded properly...

I figured it must be some browser based script prevention which doesn't let you parse the page automatically...


Try setting the User-Agent header on the request. Ex:

String ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30";
Jsoup.connect("http://example.com").userAgent(ua).get().html();
0

精彩评论

暂无评论...
验证码 换一张
取 消