JSOUP - How to crawl a “login required” page using JSOUP

回眸只為那壹抹淺笑 提交于 2019-12-01 23:17:34

Get the cookie after you login:

    Connection.Response loginForm = Jsoup.connect(url)
            .method(Connection.Method.GET)
            .execute();

    Connection.Response mainPage = Jsoup.connect(login-validation-url)
            .data("user", user)
            .data("senha", password)
            .cookies(loginForm.cookies())
            .execute();

    Map<String, String> cookies = mainPage.cookies();

    Document evaluationPage = Jsoup.connect(login-required-url)
            .cookies(cookies)
            .execute.parse();

   return evaluationPage;

When you get your second webpage, you also have to use the cookie:

(Source: I had this problem a few days ago)

So it's easier to just put the cookies in a Map:

Map<String, String> cookies = loginForm.cookies();

And submit the forms using these cookies.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!