Home > Mobile >  Why does my variable return None instead of the stock price?
Why does my variable return None instead of the stock price?

Time:04-12

I tried to scrape the stock price from

CodePudding user response:

In soup.find() use class_= parameter:

import requests
from bs4 import BeautifulSoup

url = "https://finance.yahoo.com/quote/TSLA/"

GetUrl = requests.get(url)
soup = BeautifulSoup(GetUrl.text, "html.parser")

# use class_="..."
StockPrice = soup.find(class_="Fw(b) Fz(36px) Mb(-4px) D(ib)")

print(StockPrice.text)

Prints:

975.93
  • Related