I am new to learning Python and trying to make a web scraper app but ran into the following error. This is not a complete code but I cannot go ahead if this issue is not resolved first.
Any help will be highly appreciated!
AttributeError: 'NoneType' object has no attribute 'get_text'
import requests
from bs4 import BeautifulSoup
url = "https://www.amazon.co.uk/b?node=13978643031&pf_rd_r=7WY9X56GFTSX0ZTD0VQQ&pf_rd_p=7510143e-2d7f-4e64-a435-f4e242b0abc4"
headers = {
"user-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36"}
price = 389
def getPrice():
page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id="productTitle").get_text().strip()
print(title)
if __name__ == "__main__":
getPrice()
Error:
Traceback (most recent call last): File "/Users/sumeet/vs_code_py/app.py", line 18, in getPrice() File "/Users/sumeet/vs_code_py/app.py", line 13, in getPrice title = soup.find(id="productTitle").get_text().strip() AttributeError: 'NoneType' object has no attribute 'get_text'