import bs4, requests
url = requests.get(f'https://www.marketwatch.com/investing/stock/aapl?mod=over_search')
soup = bs4.BeautifulSoup(url.text,'lxml')
print(soup.find("div",{"class": "intraday__data"}).find("h3",{"class": "intraday__price"}).find("bg-quote"))
OUTPUT
< bg-quote channel="/zigman2/quotes/202934861/composite,/zigman2/quotes/202934861/lastsale" class="value" field="Last" format="0,0.00" session="pre">141.97< /bg-quote>
It gives me an error when I type .text in the last of the last line and here is the error
AttributeError Traceback (most recent call last) ~/Desktop/Python/playground.py in 2 url = requests.get(f'https://www.marketwatch.com/investing/stock/aapl?mod=over_search') 3 soup = bs4.BeautifulSoup(url.text,'lxml') ----> 4 print(soup.find("div",{"class": "intraday__data"}).find("h3",{"class": "intraday__price"}).find("bg-quote")).text
AttributeError: 'NoneType' object has no attribute 'text'
I just want to extract the price, any ideas?