I am trying to scrape the price of a stock off of yahoo finance as it updates every 5 seconds, but I cannot figure out a way to get the most recent stock price. Only the open and close price. I believe my problem is that I am trying to scrape data that is dynamic, changes constantly. Does anyone know a solution for this?
import requests
from bs4 import BeautifulSoup
#Which Symbol are you searching
#t_symbol = input("What stock are you searching?")
def getData(t_symbol):
url = f'https://finance.yahoo.com/quote/{t_symbol}'+f'?p={t_symbol}&.tsrc=fin-srch'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
price = soup.find('fin-streamer', {'class':'Fw(b) Fz(36px) Mb(-4px) D(ib)'}).get('value')
print(price)
#webbrowser.open(url)
return price
getData('NIO')