I just started a python web course and I was trying to parse HTML Data using BeautifulSoup and I came across this error . I researched but couldnt find any precise and certain solution . So here is the piece of code :
import requests
from bs4 import BeautifulSoup
request = requests.get("http://www.johnlewis.com/toms-berkley-slipper-grey/p3061099")
content = request.content
soup = BeautifulSoup(content, 'html.parser')
element = soup.find(" span", {"itemprop ": "price ", "class": "now-price"})
string_price = (element.text.strip())
print(int(string_price))
# <span itemprop="price" class="now-price"> £40.00 </span>
And this is the error I face :
C:\Users\IngeniousAmbivert\venv\Scripts\python.exe
C:/Users/IngeniousAmbivert/PycharmProjects/FullStack/price-eg/src/app.py
Traceback (most recent call last):
File "C:/Users/IngeniousAmbivert/PycharmProjects/FullStack/price-eg/src/app.py", line 8, in <module>
string_price = (element.text.strip())
AttributeError: 'NoneType' object has no attribute 'text'
Process finished with exit code 1
Any help will be appreciated