Skip to content

Instantly share code, notes, and snippets.

@firedfox
Created August 21, 2012 11:12
Show Gist options
  • Save firedfox/3414609 to your computer and use it in GitHub Desktop.
Save firedfox/3414609 to your computer and use it in GitHub Desktop.
phantomjs log into reddit
var page = require('webpage').create();
page.onLoadFinished = function() {
var username = page.evaluate(function() {
return $('span.user').children('a').html();
});
if (username !== 'cvUg338yQa') {
page.evaluate(function(username, password) {
$('input[name="user"]:first').attr('value', 'cvUg338yQa');
$('input[name="passwd"]:first').attr('value', 'GNyoqNKJK5');
$("form#login_login-main").submit();
});
} else {
console.log(username);
phantom.exit();
}
};
page.open('http://www.reddit.com/');
const USERNAME = 'cvUg338yQa';
const PASSWORD = 'GNyoqNKJK5';
var page = require('webpage').create();
page.onLoadFinished = function() {
var username = page.evaluate(function() {
return $('span.user').children('a').html();
});
if (username !== USERNAME) {
page.evaluate(function(username, password) {
$('input[name="user"]:first').attr('value', username);
$('input[name="passwd"]:first').attr('value', password);
$("form#login_login-main").submit();
}, USERNAME, PASSWORD);
} else {
console.log(username);
phantom.exit();
}
};
page.open('http://www.reddit.com/');
@webdevbrian
Copy link

does this still work? I'm trying to submit the form and it does't submit for some weird reason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment