Debug School

rakesh kumar
rakesh kumar

Posted on

AttributeError: 'NoneType' object has no attribute 'text'

Error

AttributeError                            Traceback (most recent call last)
Cell In[23], line 2
      1 first_team = soup.find('div', class_="rankings-block__banner--nation")
----> 2 first_team.text

AttributeError: 'NoneType' object has no attribute 'text'
Enter fullscreen mode Exit fullscreen mode

my code is

first_team = soup.find('span', class_="rankings-block__banner--nation")
first_team.text
Enter fullscreen mode Exit fullscreen mode

but in inspect inside span element no text is present

Image description
solution

first_team = soup.find('div', class_="rankings-block__banner--nationality")
my=first_team.text
cleaned_text = my.split()[0]
cleaned_text
Enter fullscreen mode Exit fullscreen mode

output

'PAK'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)