Reputation: 1751
I want to parse a website. However I have a behavior that I can't really explain : I get the soup through the beautifulSoup website. It is a bs4 element. However when I want to find all the mentionned balise, it says that the type of the element is None. Please find the code below:
from bs4 import BeautifulSoup
import urllib2 as web
url = "http://www.stevegtennis.com/men-atp-rankings/2015-7-6/1/all/"
soup = BeautifulSoup(web.urlopen(url).read(),'lxml')
print type(soup)
player1 = soup.findall('tr',class_="row1")
It returns the following error:
TypeError : 'NoneType' object is not callable
Help much appreciated.
Thanks in advance
Upvotes: 0
Views: 627
Reputation: 25528
You probably mean:
player1 = soup.find_all('tr',class_="row1")
rather than soup.findall
. You don't get a NameError
because BeautifulSoup implements __getattr__
to return computed attributes and this returns None
if it doesn't have the one you ask for.
Upvotes: 2