Skip to content
Advertisement

nonetype object has no attribute text error while scraping data

when i try to scrap data from this amazon link. I got AttributeError: 'NoneType' object has no attribute 'text'

My Code:

JavaScript

I think that the laptop_rating variable store the content in string format even if we not include .text. I’m thinking that might be the reason for getting NoneType error, as we are extracting text from text. Anyway that’s not the issue. How to extract the price or rating from that link?

Advertisement

Answer

At least from my tests, that page is recognizing automated access and blocks it. You need to use something like cloudscraper to do it. The following code will return the expected results (adapt to your own circumstances):

JavaScript

This will print out in terminal:

JavaScript

Cloudscraper’s details and install instructions: https://pypi.org/project/cloudscraper/

Advertisement