Skip to content Skip to sidebar Skip to footer

Python & Beautiful Soup - Searching Result Strings

I am using Beautiful Soup to parse an HTML table. Python version 3.2 Beautiful Soup version 4.1.3 I am running into an issue when trying to use the findAll method to find the

Solution 1:

findAll() returns a result list, you'd need to loop over those or pick one to get to another contained element with it's own findAll() method:

table = soup.findAll('table')[1]
rows = table.findAll('tr')
for row in rows:
    cols = rows.findAll('td')
    print(cols)

or pick one row:

table = soup.findAll('table')[1]
rows = table.findAll('tr')
cols = rows[0].findAll('td')  # columns of the *first* row.
print(cols)

Note that findAll is deprecated, you should use find_all() instead.


Post a Comment for "Python & Beautiful Soup - Searching Result Strings"