how to maintain variable cookies and sessions with jsoup?

前端 未结 2 1416
野性不改
野性不改 2020-12-14 05:16
public boolean isGood(String path)
{
    if (p != path)
    {
        good = false;
    }

    if (good)
    {
        try 
        {
            Connection connecti         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 05:29

    +1 for BalusC

    I changed some in your code and it works for me, so you get cookie from site and only than get Document

    public Document get(String url) throws IOException {
        Connection connection = Jsoup.connect(url).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
        Connection.Response response = connection.execute();
        connection.cookies(response.cookies());
        return connection.get();
    }
    

提交回复
热议问题