-
-
Save renanmpimentel/d07646fda10e924a1143c84a0bd6eeaf to your computer and use it in GitHub Desktop.
function startOfx() { | |
return ` | |
OFXHEADER:100 | |
DATA:OFXSGML | |
VERSION:102 | |
SECURITY:NONE | |
ENCODING:USASCII | |
CHARSET:1252 | |
COMPRESSION:NONE | |
OLDFILEUID:NONE | |
NEWFILEUID:NONE | |
<OFX> | |
<BANKMSGSRSV1> | |
<STMTTRNRS> | |
<STMTRS> | |
<BANKTRANLIST>`; | |
} | |
function endOfx() { | |
return ` | |
</BANKTRANLIST> | |
</STMTRS> | |
</STMTTRNRS> | |
</BANKMSGSRSV1> | |
</OFX>`; | |
} | |
function bankStatement(date, amount, description) { | |
return ` | |
<STMTTRN> | |
<TRNTYPE>OTHER</TRNTYPE> | |
<DTPOSTED>${date}</DTPOSTED> | |
<TRNAMT>${amount}</TRNAMT> | |
<MEMO>${description}</MEMO> | |
</STMTTRN>`; | |
} | |
function normalizeAmount(text) { | |
return text.replace('.', '').replace(',','.'); | |
} | |
function normalizeDate(date) { | |
date = date.split('/'); | |
return date[2]+date[1]+date[0] | |
} | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
function generateOfx() { | |
var dollar = parseFloat(normalizeAmount(getElementByXpath('//*[@id="resdespbra"]/table/tbody/tr[1]/td[3]/table/tbody/tr[4]/td[2]/strong').innerText)) | |
var ofx = startOfx(); | |
var inputs = document.querySelectorAll('.trClaro'); | |
inputs.forEach(function(el, index, array){ | |
var date = normalizeDate(el.getElementsByTagName('td')[0].innerText); | |
var description = el.getElementsByTagName('td')[1].innerText; | |
if(normalizeAmount(el.getElementsByTagName('td')[3].innerText) > 0) { | |
var amount = normalizeAmount(el.getElementsByTagName('td')[3].innerText) * dollar; | |
} else { | |
var amount = normalizeAmount(el.getElementsByTagName('td')[2].innerText); | |
} | |
ofx += bankStatement(date, amount, description); | |
}); | |
ofx += endOfx(); | |
console.log(ofx); | |
} |
O site do Santander mudou, teria que revisar o script.
Eu não uso mais Santander, por isso eu não atualizei o script.
Olá pessoal,
Eu criei uma extensão que está disponível aqui (https://github.com/delanohelio/santander-export-extension). O propósito foi gerar o OFX para usar no Organnize.
Tem funcionado para mim.
Vou testar seu script, @delanohelio. Muito obrigado.
Pessoal, fiz uma tentativa de resolver pra mim no Neon Pejota tambem, mas tentei fazer uma engine mais flexivel. Se quiserem testar no Santander, seria bem legal... Só precisa adicionar o schema com os selectors certos!
Olá pessoal,
Eu criei uma extensão que está disponível aqui (https://github.com/delanohelio/santander-export-extension). O propósito foi gerar o OFX para usar no Organnize.
Tem funcionado para mim.
Como faço para utilizar?
Você ainda usa este script? Se sim, em que página, especificamente? Tenho procurado há tempos por algo pra gerar o OFX do Santander sem sucesso.