Skip to content

Instantly share code, notes, and snippets.

@detro
Forked from davisford/script-log.js
Created October 8, 2012 17:05
Show Gist options
  • Save detro/3853638 to your computer and use it in GitHub Desktop.
Save detro/3853638 to your computer and use it in GitHub Desktop.
phantom cookies: now cookies are PERSISTENT as expected
var page = require('webpage').create();
phantom.cookiesEnabled = true;
console.log('\n\n cookies we know about => \n\n' + JSON.stringify(phantom.cookies, null, 2));
// spoof user-agent
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0';
const USER = 'cvUg338yQa';
const PASS = 'GNyoqNKJK5';
page.onLoadFinished = function() {
var user = page.evaluate(function () {
return $('span.user').children('a').html();
});
if (user !== USER) {
console.log('Need to Login...');
page.evaluate(function(username, password) {
$('input[name="user"]:first').attr('value', username);
$('input[name="passwd"]:first').attr('value', password);
document.querySelector("#rem-login-main").checked="checked"; //<------- this is what you need to make Cookies persiste beyond the Session
$("form#login_login-main").submit();
}, USER, PASS);
} else {
console.log('Logged in!');
phantom.exit();
}
};
page.open('http://www.reddit.com');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment