Issue
I'm trying to read a page with python and print each element for the ratings. I've got a AttributeError: 'NoneType' object has no attribute 'text'
error and I don't understand how to fix it.
Here is my code:
rating = movie.find('td', class_='ratingColumn imdbRating').strong.text
if rating:
try:
print(rating)
except AttributeError:
print("no rating")
Solution
You can simply check for "NoneType" before printing .text
rating = movie.find('td', class_='ratingColumn imdbRating').strong
if rating:
print(rating.text)
else:
print("no rating")
Answered By - ytung-dev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.