Jsoup设置了Accept-Language

时间:2013-06-27 05:10:34

标签: java parsing jsoup

是否有可能为Jsoup连接设置Accept-Language参数。 我试过了:

Jsoup.connection(url).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0").get();
Jsoup.connection(url).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").get();

但不起作用......

1 个答案:

答案 0 :(得分:12)

您必须将Header添加到Connection,如下所述

Jsoup.connection(url)
        .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0")
        .header("Accept-Language", "en")
        .header("Accept-Encoding","gzip,deflate,sdch");//can add as many as you like
        .get();