Created
September 23, 2020 12:56
-
-
Save zakirangwala/4b651877260800413334261f33cab43d to your computer and use it in GitHub Desktop.
Tutorial Code : Stock Price Real-Time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import libraries | |
from bs4 import BeautifulSoup | |
import requests | |
# Configure Browser Header and URL | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'} | |
URL = '' | |
# Check Price of stock | |
def check_price(): | |
try: | |
page = requests.get(URL, headers=headers) | |
soup = BeautifulSoup(page.content, 'html.parser') | |
price = soup.find( | |
class_='Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)').get_text() | |
title = soup.find(class_='D(ib) Fz(18px)').get_text() | |
currency = soup.find(class_='C($tertiaryColor) Fz(12px)').get_text() | |
currency = currency[-3:] | |
except AttributeError as e: | |
return False | |
return currency, title, price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment