Extract Bitcoin Price In Realtime

This article talks about how can we read web pages and extract current Bitcoin prices. Now, to perform this web scrapping, we need  a few things:

  • Website
  • Web scrapping libraries/tools 
  • Programming language

Website

This is the website from which we are going to read the price of Bitcoin. There are many websites, from which you can read this data but for this article, I'm using Coinmarketcap.com and its URL is 

https://coinmarketcap.com/currencies/bitcoin

Extract Bitcoin Price In Realtime

Web Scraping Libraries/Tools

There are many web scraping libraries and tools available in the market. Below is the list of my recommendations:

  • Beautiful Soup
  • Scrapy
  • Requests (HTTP for humans)
  • LXML
  • Selenium

If you want to know the brief of any of these, you can watch out my video. For this article, I'm using Requests along with Beautiful Soup.

Programing Language

This article uses Python as a programming language

import requests
from bs4 import BeautifulSoup as bs

URL = "https://coinmarketcap.com/currencies/bitcoin/"
reponse = requests.get(URL)

htmlContent = bs(reponse.content,'html.parser')

divTagContent = htmlContent.find('div',{'class':'priceValue'})
priceTag = divTagContent.select_one('span')
print(f"Current price of Bitcoin is {priceTag.text}")

To understand, which HTML tag is holding this data, you can use any developer tool. If you have Chrome, then you can open coinmarketcap.com website and press F12. Doing this will open a developer tool window as shown below,

Extract Bitcoin Price In Realtime

Hope you enjoyed extracting data from a web page. You can also watch out this implementation in my recording.


Recommended Free Ebook
Similar Articles