Created
April 17, 2017 02:23
-
-
Save andresmachado/d3a670759932ca40a47430b5c2c6821e to your computer and use it in GitHub Desktop.
Import all active banks in Brazil
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Apr 5 15:50:49 2017 | |
@author: andre | |
""" | |
import json | |
from bs4 import BeautifulSoup | |
from urllib.request import Request, urlopen | |
url = 'http://www.buscabanco.org.br/AgenciasBancos.asp' | |
request = urlopen(url) | |
response = request.read() | |
soup = BeautifulSoup(response, 'html.parser') | |
table = soup.find_all('table')[4] | |
rows = table.find_all('tr') | |
banks = [] | |
banks_dict = [] | |
for r in rows: | |
cols = r.find_all('td') | |
cols = [element.text.strip() for element in cols] | |
banks.append([ele for ele in cols]) | |
banks = banks[2:len(banks) - 2] | |
for b in banks: | |
bank_dict = {'code': b[0] if b[0] else '000', 'name': u'{}'.format(b[1])} | |
banks_dict.append(bank_dict) | |
banks_Json = json.dumps(banks_dict) | |
with open('banksBr_Json.json', 'w') as f: | |
f.write(banks_Json + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment