antuan55 antuan55 - 1 year ago 66
Python Question

Python BeautifulSoup: Iterating over a table

I want to iterate over every TD of each TR tag. So, for example, if I get all tables:

trList = tbody.findAll('tr')

Later I want to get all the TD tags of each TR element separately.

Something like:

td[1] # I wanted to get this TD of every TR

td[1] # this one as well

In a normal situation, I'd get it with a nested loop.

Is it possible to do that?

Answer Source

Yes you can, use the same function findAll

trList = tbody.findAll('tr')
for tr in trList:
    tdList = tr.findAll('td')
    for td in tdList:
        // here you got each td
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download