Skip to content

Instantly share code, notes, and snippets.

@mping
Last active February 9, 2017 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mping/17911ff5de2cfc356d87017276a33126 to your computer and use it in GitHub Desktop.
Save mping/17911ff5de2cfc356d87017276a33126 to your computer and use it in GitHub Desktop.
Nightmarejs to fetch ebank data
var electron = require("electron")
var Nightmare = require("nightmare")
require('nightmare-inline-download')(Nightmare)
//$ node xxx.js USER PW
// ^ in some shells, that space prevents the cmd to be saved in shell history
var user = process.argv[2]
var pass = process.argv[3]
Nightmare({show: true})
.goto ("https://caixadirectaonline.cgd.pt/cdo/login.seam")
.wait ("a.direct-link.desktop")
.click( "a.direct-link.desktop")
.wait ("#input_cx1")
// main page, put account
.type ("#input_cx1", user)
.click( "input#login_btn_1")
.wait ("#zeroHPModalPanel")
// login form, put pw
.click( "#zeroHPModalPanel input")
.type ("input#passwordInput", pass)
.click( ".tecladoVirt input[type=\"submit\"]")
.wait ("#zeroHPModalPanel2")
// logged in, close logged in dialog
.click( "#zeroHPModalPanel2 input")
.wait (".wa_firstnav")
// got a cookie, lets go to movements page
.goto ("https://caixadirectaonline.cgd.pt/cdo/private/contasaordem/consultaSaldosMovimentos.seam")
.wait ("table.mgtop")
.evaluate(function() {
var rows = document.querySelectorAll("table.mgtop td")
return Array.prototype.map.call(rows, function(cell) {
var child = cell.firstChild
return child && child.nodeName === "SPAN" ? child.title : cell.innerText
})
})
.then(function(res){
console.log(res)
}, console.log.bind(console))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment