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)
6 Réponses
+ 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?
+ 2
Slick Slick
I omitted price and It worked. They may have changed the html code. Thanks
+ 1
soup2.find(whatever) returns None. So when you call .get_text() on None, you get an error.
+ 1
Yeah it happens, no worries!
0
Slick I am watching a video on YouTube. It works for him but not for me
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.