Created
November 11, 2019 15:27
-
-
Save Rillke/9cefde955c0eddf61909ea6183f2c5b0 to your computer and use it in GitHub Desktop.
Extract data from N°26 bank transactions page
This file contains 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
let balance = 0; | |
let transactions = []; | |
for (elem of document.querySelectorAll('a[href^="/transactions"]')) { | |
console.log(Array(20).join('-')); | |
const parent = elem.parentNode; | |
if (!parent) { | |
console.warn('skip [parent]', elem, elem.innerText); | |
continue; | |
} | |
const amountNode = parent.nextSibling; | |
if (!amountNode) { | |
console.warn('skip [sibling]', elem, elem.innerText); | |
continue; | |
} | |
const amountText = amountNode.innerText; | |
if (amountText.indexOf('My Account') !== -1) { | |
console.warn('skip [balance]', elem, elem.innerText); | |
continue; | |
} | |
const cleanAmountText = amountText | |
.replace(/.*\r?\n?[^−]*(−?€\d+\.\d+).*/, '$1') | |
.replace('−', '-') | |
.replace('€', ''); | |
const amount = parseFloat(cleanAmountText); | |
if (isNaN(amount)) { | |
console.warn('skip [NaN]', amountText, cleanAmountText, elem, elem.innerText); | |
continue; | |
} | |
const subject = elem.innerText; | |
transactions.push( { subject: subject, amount: amount } ); | |
balance += amount; | |
} | |
console.log('TOTAL BALANCE: ' + balance); | |
console.log(JSON.stringify(transactions)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that under downloads there is the possibility to export CSV and PDF, but these may not include the newest transactions.