-
-
Save detro/3853638 to your computer and use it in GitHub Desktop.
phantom cookies: now cookies are PERSISTENT as expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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