Last active
August 29, 2015 14:19
-
-
Save mherwig/cdf446154ac6ed02f671 to your computer and use it in GitHub Desktop.
Example for web scraping using CasperJS/SlimerJS
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
// Usage: casperjs --ssl-protocol=any --engine=slimerjs paypal.js | |
// Open in browser: http://localhost:8083/get | |
var email = '', | |
password = ''; | |
var casper = require('casper').create({ | |
verbose: true, | |
logLevel: "debug" | |
}), | |
webserverTest = require("webserver").create(); | |
webserverTest.listen(8083, function(request, response) { | |
if (request.url == '/get') { | |
casper.start(); | |
casper.userAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'); | |
casper.thenOpen('https://www.paypal.com/signin/', function() { | |
this.fill('form', { | |
'email': email, | |
'password': password | |
}, true); | |
}); | |
casper.then(function() { | |
casper.waitForSelector('.balanceNumeral', function() { | |
response.statusCode = 200; | |
var myBalance = this.getHTML('div.balanceNumeral span'); | |
var jsonData = { | |
balance: myBalance, | |
transactions: [] | |
}; | |
var transactionItems = this.getElementsInfo('div.transactionItem'); | |
var item; | |
for (item in transactionItems) { | |
jsonData.transactions.push({ | |
text: transactionItems[item].text | |
}); | |
} | |
response.write(JSON.stringify(jsonData)); | |
response.close(); | |
}); | |
}); | |
casper.run(function() {}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I patched /usr/local/bin/casperjs so that I'll have a headless slimerjs with xvfb (sudo apt-get install xvfb):