Hi All,

I am trying to scrape a piece of HTML similar to the below where I want beautiful soup to return something like:

List Price, £28,410
Body Style, Open Car

etc etc.

I thought if I did this:

soup = BeautifulSoup(html_doc)
tag = soup.find_all('tr')
tag_td = tag[0].find('td')
tag_b = tag[0].find('b')
print(tag_td.text)
print(tag_b.text)

It would return "List Price, £28,410" but I got an error:

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

I did try removing the .text but then I just got none so I think my find is actually not finding anything. I don't need to be spoon fed but I am literally pulling my hair out.

Thank you so much,
JD

<table width="100%" class='TableList' cellspacing="1" cellpadding="3" border="0"
            style='margin-bottom: 10px;'>
            <tr class='TableListHead'>
                <th colspan="2">
                    Basics
                </th>
            </tr>
            <tr class='rc1'>
                <td>
                    List Price
                </td>
                <td align="right">
                    <b>£28,410</b>
                </td>
            </tr>
            <tr class='rc2'>
                <td>
                    Body style
                </td>
                <td align="right">
                    <b>Open Car</b>
                </td>
            </tr>
            <tr class='rc1'>
                <td>
                    Gearbox
                </td>
                <td align="right">
                    <b>5-spd</b>
                </td>
            </tr>
            <tr class='rc2'>
                <td>
                    Doors
                </td>
                <td align="right">
                    <b>-</b>
                </td>
            </tr>
            <tr class='rc1'>
                <td>
                    Seats
                </td>
                <td align="right">
                    <b>-</b>
                </td>
            </tr>

</table>

From what I can see, there's no <td> in tag[0]. Sure you don't want tag[1]?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.