0

My problem is that i keep getting this error "AttributeError: 'NoneType' object has no attribute 'get_text'"

Can someone please explain what can I do to fix this type of error. Thanks

This is using python and BeautifulSoup inside jupiternb

URL = 'https://www.amazon.com/Funny-Data-Systems-Business-Analyst/dp/B07FNW9FGJ/ref=sr_1_3?dchild=1&keywords=data%2Banalyst%2Btshirt&qid=1626655184&sr=8'

headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"}

page = requests.get(URL, headers=headers)

soup1 = BeautifulSoup(page.content, "html.parser")

soup2 = BeautifulSoup(soup1.prettify(), "html.parser")

title = soup2.find(id='title').get_text()

print(title)

Results:

AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_1944\3978847060.py in <module>
     11 soup2 = BeautifulSoup(soup1.prettify(), "html.parser")
     12 
---> 13 title = soup2.find(id='title').get_text()
     14 
     15 print(title)

AttributeError: 'NoneType' object has no attribute 'get_text'
  • Actually soup2.find(id='title') returns None. Try to figure out why. – FLAK-ZOSO Dec 23 '22 at 13:32
  • It probably returns `None` because Amazom doesn't make it that easy to make automated requests. Trying out your code gives back the follwoing message in the HTML: `To discuss automated access to Amazon data please contact api-services-support@amazon.com. For information about migrating to our APIs refer to our Marketplace APIs at https://developer.amazonservices.com/ref=rm_c_sv, or our Product Advertising API at https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html/ref=rm_c_ac for advertising use cases` – Clasherkasten Dec 23 '22 at 13:35

0 Answers0