I want my casper to log in and stay logged in during the session. Is it possible? If so, how?
Asked
Active
Viewed 1.5k times
12
-
3Did my answer solve your question? Or do you need some more clarification? @Euphe – Thomas Jan 06 '14 at 16:17
-
http://stackoverflow.com/questions/15907800/how-to-persist-cookies-between-different-casperjs-processes – Ciro Santilli OurBigBook.com Nov 16 '15 at 16:33
2 Answers
21
If you want to store cookies in CasperJS, you can use the PhantomJS cookiejar, which is accesible natively through CasperJS.
Simply add following option when you launch CasperJS:
--cookies-file=cookies.txt
Your cookies will be stored in that file. Even after exiting CasperJS, if you call CasperJS with this option, you'll have access to those cookies again.
Hope that helps.
Thomas
- 2,070
- 3
- 16
- 21
-
-
1If you launch CasperJS with the option like this: "casperjs test --cookies-file=cookies.txt scraper.js" it should definetly work. What version of PhantomJS are you using? – Thomas Jan 08 '14 at 10:59
3
What do you mean? are you just sitting idle in session? Typically you do not want casper.exit() to be called. So if there are times you want to wait a bit but stay logged in you should define that time in a
casper.wait(60000, function () {
});
Chris Hawkes
- 11,923
- 6
- 58
- 68
-
Let's say casper submitted a login form, logged in. If casper navigates to a different page, does it stay logged in? If I restart casper, will it stay logged in after reconnecting? – Euphe Jan 03 '14 at 16:37
-
1No if you restart CasperJS it will kill your existing session and cache. – Chris Hawkes Jan 03 '14 at 18:07