Friends, I get an error with this, do you know why? It says: 'Nonetype' object has no Attribute 'get_text' | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Friends, I get an error with this, do you know why? It says: 'Nonetype' object has no Attribute 'get_text'

page = requests.get(URL, headers=headers) soup1 = BeautifulSoup(page.content, "html.parser") soup2 = BeautifulSoup(soup1.prettify(), "html.parser") title = soup2.find(id='productTitle').get_text() price = soup2.find(id='priceblock_ourprice').get_text() print(title) print(price)

1st Nov 2021, 9:08 AM
Tree
Tree - avatar
6 Answers
+ 2
Alright, well mabey don't do that. Have you looked at the documentation to see what .get_text() does, what it expects to get_text from, and how?
1st Nov 2021, 9:20 AM
Slick
Slick - avatar
+ 2
Slick Slick I omitted price and It worked. They may have changed the html code. Thanks
1st Nov 2021, 9:25 AM
Tree
Tree - avatar
+ 1
soup2.find(whatever) returns None. So when you call .get_text() on None, you get an error.
1st Nov 2021, 9:13 AM
Slick
Slick - avatar
+ 1
Yeah it happens, no worries!
1st Nov 2021, 9:26 AM
Slick
Slick - avatar
0
Slick I am watching a video on YouTube. It works for him but not for me
1st Nov 2021, 9:18 AM
Tree
Tree - avatar
0
The same happened to me. The error is that price = soup1.find(id='priceblock_ourprice') returns None. And because? because on the page 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-3&customId=B0752XJYNL&th=1&customization_MCAkense% 23B0752XJYNL The shirt currently has no price, so id='priceblock_ourprice' this doesn't exist.
15th Mar 2023, 10:08 PM
Lucas Zanazzo
Lucas Zanazzo - avatar