Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2024 new site design #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions itauscraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ const os = require('os')

const stepLogin = async (page, options) => {
// Open homepage and fill account info
console.log('Configuring user-agent...')
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36')
await page.waitForTimeout(300)
console.log('Opening bank homepage...')
console.debug('Itaú url:', options.itau.url)
await page.goto(options.itau.url)
console.log('Homepage loaded.')
await page.type('#agencia', options.branch)
await page.type('#conta', options.account)
await page.type('#idl-menu-agency', options.branch)
await page.type('#idl-menu-account', options.account)
console.log('Account and branch number has been filled.')
await page.waitForTimeout(500)
await page.click('.login_button')
await page.click('#idl-btn-login-ok')

if(!!options.name){
if (!!options.name) {
console.log('Opening account holder page...');
await page.waitForTimeout(2000)
await stepAwaitRegularLoading(page)
Expand All @@ -28,7 +31,7 @@ const stepLogin = async (page, options) => {
const names = await page.$$('ul.selecao-nome-titular a[role="button"]');
for (const name of names) {
const text = await page.evaluate(element => element.textContent, name);
if(text.toUpperCase() == options.name.toUpperCase()){
if (text.toUpperCase() == options.name.toUpperCase()) {
name.click();
console.log('Account holder selected.')
}
Expand Down Expand Up @@ -83,14 +86,28 @@ const stepExport = async (page, options) => {
console.log('Menu has been closed')

// Select period of days
await page.select('cpv-select[model=\'pc.periodoSelecionado\'] select', options.days.toString())
console.log('Selected period of days on the filters')
await stepAwaitRegularLoading(page)
const currentDays = await page.evaluate(() => document.querySelector('#periodoFiltroName').innerText);
if (currentDays !== 'últimos ' + options.days.toString() + ' dias') {
await page.evaluate((days) => {
const items = Array.from(document.querySelectorAll('ul.form-element-group__select-options li'))
const item = items.find(el => el.textContent.trim() === 'últimos ' + days + ' dias')
if (item) {
item.click()
}
}, options.days.toString())

console.log('Selected period of days on the filters')
await stepAwaitRegularLoading(page)
}

// Sort by most recent transactions first
await page.select('cpv-select[model=\'app.ordenacao\'] select', 'maisRecente')
console.log('Sorted by most recent transactions first')
await stepAwaitRegularLoading(page)
const currentOrder = await page.evaluate(() => document.querySelector('#selectidName').innerText);
if (currentOrder !== 'mais recente') {
await page.evaluate(() => document.querySelector('li[data-id=\'maisRecente\']').click());

console.log('Sorted by most recent transactions first')
await stepAwaitRegularLoading(page)
}

// configure Download Trigger
let triggerDownload = (fileFormat) => { exportarExtratoArquivo('formExportarExtrato', fileFormat) }// eslint-disable-line
Expand Down Expand Up @@ -120,13 +137,13 @@ const stepAwaitRegularLoading = async (page) => {
const stepCloseStatementGuide = async (page) => {
await page.waitForSelector('.feature-discovery-extrato button.hopscotch-cta', { timeout: 4000 })
.then(() => page.click('.feature-discovery-extrato button.hopscotch-cta')) // eslint-disable-line
.catch(() => {})
.catch(() => { })
}

const stepClosePossiblePopup = async (page) => {
await page.waitForSelector('div.mfp-wrap', { timeout: 4000 })
.then(() => page.evaluate(() => popFechar())) // eslint-disable-line
.catch(() => {})
.catch(() => { })
}

const mapPasswordKeys = async (page) => {
Expand Down