I try to scrape stockprices on yahoo finance and the piece of code works on alot of stock tickers but stock ticker "ISPA.DE" does not work for some reason. it gives AttributeError: 'NoneType' object has no attribute 'text'
import requests
from bs4 import BeautifulSoup
def stockprice(stock_ticker):
url = "https://finance.yahoo.com/quote/" + str(stock_ticker) + "?p=" + str(stock_ticker) + "&.tsrc=fin-srch"
print(url)
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
price = soup.find('fin-streamer', {"class": 'Fw(b) Fz(36px) Mb(-4px) D(ib)'}).text
print(price)
stockprice("ISPA.DE")
I tried several ways but with no result. Other tickers do work...
Try to set
User-AgentHTTP header in request:Prints: