Java 我如何接受jsoup的cookies?

Java 我如何接受jsoup的cookies?,java,html,cookies,jsoup,screen-scraping,Java,Html,Cookies,Jsoup,Screen Scraping,我正试图从一份数字报纸上搜集评论。我正在用Java和Jsoup做这件事。问题是我必须接受来自网站的cookies来搜索通知。。。该网站是 我尝试连接Jsoup.connect(url)并从响应中获取cookie,以使用这些cookie执行另一个请求,但没有成功 Connection conexion = null; Document doc = null; Response response = null; Map<String, String> co

我正试图从一份数字报纸上搜集评论。我正在用Java和Jsoup做这件事。问题是我必须接受来自网站的cookies来搜索通知。。。该网站是

我尝试连接Jsoup.connect(url)并从响应中获取cookie,以使用这些cookie执行另一个请求,但没有成功

    Connection conexion = null;
    Document doc = null;
    Response response = null;
    Map<String, String> cookies = new TreeMap<String, String>();
    try {

        // First request.
        Connection connection1 = Jsoup.connect(url);
        for (Entry<String, String> cookie : cookies.entrySet()) {
            connection1.cookie(cookie.getKey(), cookie.getValue());
        }
        Response response1 = connection1.execute();
        cookies.putAll(response1.cookies());


        // Second request.
        Connection connection2 = Jsoup.connect(url);
        for (Entry<String, String> cookie : cookies.entrySet()) {
            connection2.cookie(cookie.getKey(), cookie.getValue());
        }
        Response response2 = connection2.execute();
        cookies.putAll(response2.cookies());
        doc = response2.parse();

        } catch (IOException ex) {
               System.out.println("Exception raised: " + ex.getMessage());
    }
    return doc;
Connection conexion=null;
单据单据=空;
响应=空;
映射cookies=新树映射();
试一试{
//第一个请求。
connection1=Jsoup.connect(url);
对于(条目cookie:cookies.entrySet()){
connection1.cookie(cookie.getKey(),cookie.getValue());
}
Response response1=connection1.execute();
cookies.putAll(response1.cookies());
//第二个请求。
connection2=Jsoup.connect(url);
对于(条目cookie:cookies.entrySet()){
connection2.cookie(cookie.getKey(),cookie.getValue());
}
Response response2=connection2.execute();
cookies.putAll(response2.cookies());
doc=response2.parse();
}捕获(IOEX异常){
System.out.println(“引发异常:+ex.getMessage());
}
退货单;
我在一些帖子中看到过这段代码,但它对我没有帮助:( 我想请求url“https://elpais.com/buscador/?qt=Espa%C3%B1a+Politica&sf=1&np=1&bu=ep&of=html”并通过通知获得回复。
谢谢。

不,我刚收到html,但没有收到通知,因为您需要接受cookies才能在回复中收到它们。是的,我尝试了,得到了,但我需要使用Java:(是的,没错,第二个OneNote,我刚收到html,但没有通知,因为你需要接受Cookie才能在回复中收到它们。是的,我尝试了,我得到了,但我需要用Java来做:(是的,没错,第二个。)