Created
May 19, 2015 09:18
-
-
Save jadehopepunk/dca9d9582a2cd3facd1f to your computer and use it in GitHub Desktop.
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
module.exports = () -> | |
request = require('request').defaults( | |
headers: | |
'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0', | |
'Accept-Language': "en-US,en;q=0.5", | |
'Connection': "keep-alive" | |
) | |
cheerio = require('cheerio') | |
request.post 'https://fetlife.com/session', {jar: true, followRedirect: true, form: {nickname_or_email: 'make-you-a-man', password: 'studmuffin', utf8: '✓'}}, (error, response, body) -> | |
if !error && response.statusCode == 302 | |
request 'https://fetlife.com/users/3506921', {jar: true, followRedirect: false}, (error, response, body) -> | |
if !error && response.statusCode == 200 | |
console.log "Profile page fetched" | |
console.log "setting up cheerio" | |
$ = cheerio.load(body) | |
username = $('#main_content h2')[0].childNodes[0].data.trim() | |
console.log "username is #{username}" | |
else | |
console.log("Profile page failed with #{response.statusCode}: #{JSON.stringify(response)}") | |
else | |
console.log("Login failed with #{response.statusCode}: #{JSON.stringify(response)}") | |
console.log 'starting' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment