Skip to content

Instantly share code, notes, and snippets.

@lessandro
Created March 5, 2012 15:49
Show Gist options
  • Save lessandro/1978928 to your computer and use it in GitHub Desktop.
Save lessandro/1978928 to your computer and use it in GitHub Desktop.
Extrato detalhado do site do BB. Retorna uma lista de tuplas (day, description, detail, amount)
# author: Lessandro Z. Mariano
# https://gist.github.com/1978928
import decimal
import lxml.html
import re
import requests
ag = raw_input('agencia (formato 0000-0): ')
cc = raw_input('conta (formato 00000-0): ')
pw = raw_input('senha (formato 00000000): ')
headers = {
'User-Agent': 'android 2'
}
s = requests.session(headers=headers)
url = 'https://mobi.bb.com.br/iphone/'
r = s.post(url)
action = re.search('bb.contr.*Login', r.content).group(0)
url += action
data = {
'titular': '01',
'dependenciaOrigem': ag,
'numeroContratoOrigem': cc,
'senhaConta': pw,
'botaoOk': 'Entrar',
'idh': '',
'iphm': '',
'hash': '',
'apld': ''
}
r = s.post(url, data=data)
r = s.get(r.headers['location'])
#r = s.get(r.headers['location'])
data = {
'rbPeriodo': '1',
'dia': '1',
'mes': '12',
'botaoOk': 'Ok'
}
url = 'https://mobi.bb.com.br/iphone/bb.contr?tr=009'
r = s.post(url, data)
html = lxml.html.fromstring(r.content)
table = html.xpath('//table')[0]
rows = table.xpath('./tr[position()>2]')
def parse_rows(rows):
day = 0
for row in rows:
if row[0].text.strip():
day = int(row[0].text)
description = row[1].text.strip()
detail = ''
if len(row[1]) > 0:
detail = row[1][1].text.strip()
amount_text = row[2][0].text
amount = decimal.Decimal(re.sub(r'[^0-9]', '', amount_text)) / 100
if ('D' in amount_text):
amount *= -1
yield (day, description, detail, amount)
for x in parse_rows(rows):
print x
@boppreh
Copy link

boppreh commented May 8, 2015

Não funciona mais, desativaram o aplicativo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment