Created
June 1, 2018 09:41
-
-
Save FelixChop/ff00db8df1859bc4514f37b1f41d78ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import os, bs4, requests | |
| import pandas as pd | |
| PATH = os.path.join("C:\\","Users","xxx","Documents","py") # you need to change to your local path | |
| res = pd.DataFrame() | |
| url = "http://bank-code.net/country/FRANCE-%28FR%29/" | |
| counter = 0 | |
| def table_to_df(table): | |
| return pd.DataFrame([[td.text for td in row.findAll('td')] for row in table.tbody.findAll('tr')]) | |
| def next_page(soup): | |
| return "http:" + soup.find('a', attrs={'rel':'next'}).get('href') | |
| while True: | |
| print(counter) | |
| page = requests.get(url) | |
| soup = bs4.BeautifulSoup(page.content, 'lxml') | |
| table = soup.find(name='table', attrs={'id':'tableID'}) | |
| res = res.append(table_to_df(table)) | |
| res.to_csv(os.path.join(os.path.join(PATH,"table.csv")), index=None, sep=';', encoding='iso-8859–1') | |
| url = next_page(soup) | |
| counter += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment