In [3]:
import requests
from bs4 import BeautifulSoup

In [9]:
resp = requests.get('https://coinmarketcap.com/coins/views/all/')
soup = BeautifulSoup(resp.content, 'html.parser')

In [22]:
tbody = soup.find_all('tbody')[0]
rows = tbody.find_all('tr')

In [14]:
historical_data_urls = []

for link in links:
    historical_data_urls.append()

In [20]:
dfs = []

for row in rows:
    link = row.find_all('a', attrs={'class': 'currency-name-container'})[0]
    historial_data_url = 'https://coinmarketcap.com{0}historical-data/?start=20000101&end={1}'.format(link.attrs['href'], datetime.datetime.today().strftime('%Y%m%d'))
    
    df = pd.read_html(historial_data_url)[0]
    
    df['currency'] = link.text
    df['symbol'] = row.find_all('td', attrs={'class': 'col-symbol'})[0].text
    
    dfs.append(df)

df = pd.concat(dfs)

df.tail()


Out[20]:
Date Open High Low Close Volume Market Cap currency symbol
45 Oct 21, 2017 0.000661 0.000918 0.000605 0.000782 142870 - Swisscoin SIC
46 Oct 20, 2017 0.000570 0.000784 0.000455 0.000782 139044 - Swisscoin SIC
47 Oct 19, 2017 0.000503 0.000574 0.000395 0.000513 187487 - Swisscoin SIC
48 Oct 18, 2017 0.000448 0.000940 0.000430 0.000503 531964 - Swisscoin SIC
49 Oct 17, 2017 0.000504 0.000560 0.000391 0.000392 169334 - Swisscoin SIC

In [21]:
df.to_csv('data/historical-data-extract.csv')

In [ ]: