Created
August 21, 2012 11:12
-
-
Save firedfox/3414609 to your computer and use it in GitHub Desktop.
phantomjs log into reddit
This file contains hidden or 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(); | |
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/'); |
This file contains hidden or 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
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/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
does this still work? I'm trying to submit the form and it does't submit for some weird reason