How can I extract the correct div from the google finance html to obtain the annual return on the stock of this url https://www.google.com/finance/quote/NVO:NYSE?window=1Y?
I made this code to webscraping this page and I cant get the correct data. How can I fix
def parse_stock_info(self, html):
soup = BeautifulSoup(html, 'html.parser')
name_tag = soup.find("div", class_="zzDege")
price_tag = soup.find("div", class_="YMlKec fxKbKc")
performance_tag = soup.find("div", class_="JwB6zf")
name = name_tag.text if name_tag else "N/A"
price = price_tag.text if price_tag else "N/A"
performance = performance_tag.text if performance_tag else "N/A"
return {
"name": name,
"price": price,
"performance": performance
}
New contributor
Eros Lamberto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.