Cryptocurrency Historical Data Scrapping in Python!

In this short blog, I will show you how to build a small scrapper in Python by using beautifulsoup and selenium in order to extract historical data of your favorite cryptocurrency from

Why Scrappying?

Scrapping historical data for a specific cryptocurrency is very useful for designing trading bots, for instance, by training a predictive model for a trading bot. If you create your model correctly, you will have a good chance at predicting future crypto prices!

Installing Beautifulsoup & Selenium

In order to extract the data, firstly we need to install "beautifulsoup," and "selenium". To do this, enter the command "pip install beautifulsoup4" in the terminal (needless to say you need to have PIP already installed). After that, you should execute ‘pip install requests’. Next, you enter `pip install selenium` then make sure you have already downloaded "chromedriver" (according to

from selenium import webdriver
import requests
import bs4
import csv


r = requests.get('')
soup = bs4.BeautifulSoup(r.text,"lxml")

tr = soup.find_all('tr',{'class':'text-right'})
for item in tr:


row0=['date','high','market cap']
with open('coinmarketExample2.csv','w',encoding='utf-8',newline='')as csvfile:
    for item in rows:

After running the code, if you get some error regarding the packages, firstly try to run "pip install ml" in the terminal to control the presence of packages on your computer. If you see the errors again, make sure that the chromedriver is well downloaded and located in your local path.

Posted by Mohammadreza in May 2020

I'm a computer security researcher and a full-stack programmer.