Retrieve Live Market Price
Accessing Share and Bombay Stock Exchange (BSE) Market price using Web scraping with the help of Python’s Beautiful Soup Package.
In this example we covered TCS share price as an example.
Here is the Python code to perform the task.
#data science with Python - TCS share and BSE Market price import bs4 import pandas as pd import requests url = 'https://www.google.com/finance/quote/TCS:NSE' result = requests.get(url) soup = bs4.BeautifulSoup(result.text,'lxml') for row in soup.find_all('div',attrs={"class" : "YMlKec fxKbKc"}): print ("TCS Share price:", row.text) url2='https://www.google.com/finance/quote/SENSEX:INDEXBOM' result2 = requests.get(url2) soup2 = bs4.BeautifulSoup(result2.text,'lxml') for row2 in soup2.find_all('div',attrs={"class" : "YMlKec fxKbKc"}): print ("BSE Market price:", row2.text)
Output of the above code is :
TCS Share price: ₹3,562.20
BSE Market price: 56,988.59These values are retrieved live on any particular day when the market is open otherwise it shows previous day’s values.