How to get these values with BeautifulSoup?

Posted by Damiano on Stack Overflow See other posts from Stack Overflow or by Damiano
Published on 2010-05-10T13:58:30Z Indexed on 2010/05/10 14:04 UTC
Read the original article Hit count: 231

Filed under:
|

Hello everybody,

I have this html table:

<table>
    <tr>
        <td class="datax">a</td>
        <td class="datax">b</td>
        <td class="datax">c</td>
        <td class="datax">d</td>
    </tr>
    <tr>
        <td class="datax">e</td>
        <td class="datax">f</td>
        <td class="datax">g</td>
        <td class="datax">h</td>
    </tr>
</table>

How to get the second and the fourth value of each <tr> ? If i do:

bs.findAll('td', {'class':'datax'})

I get:

        <td class="datax">a</td>
        <td class="datax">b</td>
        <td class="datax">c</td>
        <td class="datax">d</td>

        <td class="datax">e</td>
        <td class="datax">f</td>
        <td class="datax">g</td>
        <td class="datax">h</td>

it's correct! but I would like to have this result:

        <td class="datax">b</td>
        <td class="datax">d</td>

        <td class="datax">f</td>
        <td class="datax">h</td>

so, the values I want are -> b - d - f - h

(the second and the forth <td> of each <tr>)

Is it possible with BeautifulSoup module?

Thank you very much!

© Stack Overflow or respective owner

Related posts about python

Related posts about beautifulsoup