Reputation: 516
I can't maintain session surfing through a website once logged in.
I do can successfully login on the site (i specify that whatever the page is, after the login you will be redirected to the homepage) but then I have to move to another page. First I tried with page.open() then with page.evaluate changing the location.href window property, but in both cases unfortunately the result is that I'm not logged in anymore. I traced the login status just rendering the page on every page load event with incremental png names (1.png, 2.png, etc) . I also tried with --cookies-file=cookies.txt param but it didn't help much.
My questions are: What is the best way to "move" through site pages with phantomjs? Is there a specific way to handle sessions in these cases (maybe sending cookies manually on each .open(), just saying)?
Thanks for help.
Upvotes: 12
Views: 16418
Reputation: 3484
I had issues with the cookies file approach. The file would be written, and I could see "cookie information" in the file, but future requests would be interpreted as unauthenticated. As a last ditch effort, I simply took the page.cookies array, serialized it to JSON and saved it to a file. My next script would open the file, deserialize it to a variable and set the page.cookies to the variable. Sure enough this worked! Just thought I would pass it along.
Upvotes: 8