Skip to content

Instantly share code, notes, and snippets.

@burningtree
Created September 24, 2013 01:04
Show Gist options
  • Select an option

  • Save burningtree/6679082 to your computer and use it in GitHub Desktop.

Select an option

Save burningtree/6679082 to your computer and use it in GitHub Desktop.
/*!
* airbank-status.js
* CasperJS script for getting basic info from Airbank.cz website
* MIT License
* by Jan Stransky <jan.stransky@arnal.cz>
*
* Requirements:
* - casperjs 1.1.0+
*
* Usage:
* # casperjs airbank-status.js <username> <password>
*
* Example output:
* {
* "basic": {
* "balance": 6910.6,
* "balanceCurrency": "CZK",
* "blocked": 500.55,
* "accountNumber": "12345678/3030"
* }
* }
*/
var casper = require('casper').create({
//verbose: true,
//logLevel: 'debug',
viewportSize: { width:1024, height:768 },
pageSettings: {
userAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5'
}
});
function getInfo(){
function sanitize(str){
return $.trim(str).replace(/[\t\n]+/, '');
}
function sanitizeNumber(str){
return parseFloat(sanitize(str).replace(/[^\d,\.]+/,'').replace(',','.'));
}
// zustatek
var basicLeft = $('div.cmpDropAccountsInner .mhtAccountItemLeft');
var basicRight = $('div.cmpDropAccountsInner .mhtAccountItemRight');
return {
balance: sanitizeNumber(basicRight[0].textContent),
balanceCurrency: sanitize(basicRight[0].textContent.match(/([A-Z]{3})/)[1]),
blocked: sanitizeNumber(basicRight[1].textContent),
accountNumber: sanitize(basicLeft[1].textContent),
}
}
var info = {};
casper.start();
casper.open("https://ib.airbank.cz/").then(function(){
this.waitWhileSelector('body.bodyLoader', function(){
// login form submitting
var args = {
'login:componentWrapper:component': casper.cli.args[0],
'passwd:componentWrapper:component': casper.cli.args[1],
};
this.capture('screenshot-login.png');
this.fill("form#idb", args, false);
this.click("div.mhtLoginBoxFooter span.cmpButton a");
});
});
casper.then(function(){
this.waitForUrl('https://ib.airbank.cz/ib', function(){
this.waitWhileSelector('body.bodyLoader', function(){
// successfuly logged
this.capture('screenshot-logged.png');
// capture basic infos
info.basic = this.evaluate(getInfo);
});
});
});
casper.run(function(){
this.echo(JSON.stringify(info, false, 2));
this.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment