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]:
In [21]:
df.to_csv('data/historical-data-extract.csv')
In [ ]: