UNPKG

n26-puppeteer-scraper

Version:

n26 scraper: a tool to download account informations and transactions archive

37 lines (28 loc) 1.56 kB
const debug = require('debug') const fs = require('fs') const path = require('path') const download = require('download') const extractCRSFToken = require('./extract-csrf-token') const extractCookies = require('./extract-cookies') const log = debug('n26:download-transactions-archive') module.exports = async function (page, options = {}) { log('preparing transactions archive', options) log('navigating to https://app.n26.com/downloads') await page.goto('https://app.n26.com/downloads') const csrfToken = await extractCRSFToken(page) log('extracted csrf token', csrfToken) const cookies = await extractCookies(page) log('extracted cookies', (cookies || '').substring(0, 100)) const startDate = parseInt(+new Date(options.startDate || '2017-01-01') / 1000) * 1000 const endDate = parseInt(+new Date((options.endDate || new Date(Date.now() + 1000 * 60 * 60 * 12).toISOString()).substring(0, 10)) / 1000) * 1000 const downloadLink = `https://app.n26.com/download-csv?_csrf=${csrfToken}&startDate=${startDate}&endDate=${endDate}` log('download link', downloadLink) log('downloading transactions archive') const archive = await download(downloadLink, { headers: { Cookie: cookies } }) log('downloaded transactions archive', archive) const filepath = path.resolve(process.cwd(), 'n26-csv-transactions.csv') log(`saving transactions archive to ${filepath}`) fs.writeFileSync(filepath, archive.toString('utf8')) log(`saved transactions archive to ${filepath}`) return { csrfToken, downloadLink, archive, cookies, filepath } }