Search code examples
authenticationcookiesscreen-scrapingwebjsoup

Grabbing a cookie after clicking login?


Hi I'm making an android app that requires data that I need to login to a website to get. I've worked with JSoup before so I've been trying to use that for all of my html scraping here.

Basically the flow of things is I go to the login site using this code

LOGIN is the URL

Connection.Response res = Jsoup.connect(LOGIN)
            .data("username", "/*username*/")
            .data("password", "/*password*/")
            .method(Method.POST)
            .execute();

//get the cookies and save it in the sessionId string
Map<String, String> loginCookies = res.cookies();

Then later I'll go to another site and need to use the cookies. The problem is there's one cookie that I seem to be missing out on. I get the cookie that I have observed through the cookie monster addon to be added when just accessing the page, before pressing login. Then right after pressing log in there's another cookie added in the browser that is not in my app, and it is essential to maintaining my login status.

So how can I get this rogue cookie that is added after pressing the button?

I've looked at several postings on here and I've learned a lot about working with cookies,

Sending POST request with username and password and save session cookie

jsoup posting and cookie

Jsoup Cookies for HTTPS scraping

are the questions I've poured over already....

thanks in advance!


Solution

  • Solved this problem (I know, late response) I had to use a get method here i believe