Skip to main content


Get the Price of Cryptocurrencies in Real Time using Python

Get the Price of Cryptocurrencies in Real Time using Python

We will scrape URL such as https://www.google.com/search?q=bitcoin+price

https://www.google.com/search?q=dogecoin+price

https://www.google.com/search?q=WHAREVER_Coin+price


Get the Price of Cryptocurrencies in Real Time using Python

Here is the Code:-


# Get Crypto Rates in Real Time
from bs4 import BeautifulSoup 
import requests 
import time

def get_crypto_price(coin):
     url = "https://www.google.com/search?q="+coin+"+price"
     HTML = requests.get(url)
     soup = BeautifulSoup(HTML.text, 'html.parser')
     text = soup.find("div", attrs={'class':'BNeawe iBp4i AP7Wnd'}).find("div", attrs={'class':'BNeawe iBp4i AP7Wnd'}).text
     return text

#Choose the cryptocurrency
def main(bitcoin):
     try:
          last_price = -1
          while True:
               crypto = bitcoin 
               #Get the price of the crypto currency
               price = get_crypto_price(crypto)
               #Check if the price changed
               if price != last_price:
                    #Print the price
                    print(crypto+' price: ',price)
                    #Update the last price
                    last_price = price

               #Suspend execution for 3 seconds.
               time.sleep(3)
     except:
          print('Please Enter Valid Coin')


          

Output:-

#NOTE:- type main(<YOUR COIN>) & [ENTER]
>>> main('bitcoin')
bitcoin price:  43,01,968.93 Indian Rupee

>>> main('litecoin')
litecoin price:  15,291.76 Indian Rupee

>>> main('etherium') 
etherium price:  3,39,967.56 Indian Rupee

>>> main('pythoncoin')

Please Enter Valid Coin
>>> 

>>> main('python4fun')
	 
Please Enter Valid Coin
>>> 

>>> main('doge')
doge price:  16.48 Indian Rupee

RUN

Comments



🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍

Popular Posts

Python underline string, Python underline text, Underline python print

Python pip - Installing modules from IDLE (Pyton GUI) for python 3.7

Top 40 Python - String Processing in Python | Working with String in Python

Python Program - When was I born? / Date of Birth / MY BIRTHDAY (using Python3+)

Top 11 Essential Python Tips and Tricks





Subscribe to our Channel


Follow us on Facebook Page

Join our python facebook groups



Join us on Telegram