Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

beautifulsoup returning data as None that includes <br> tag

I have a table data like this:

<table class="tablesorter" id="dea">
<thead>
<tr>
<th class="header ">Name</th>
<th class="header">City</th>
<th class="">Address</th>
<th class="">Phone Nos</th>
<th class="">Email</th>
<th class="">Fax</th>
</tr>
</thead>
<tbody>

<tr class="info">
<td style="font:bold 12px Tahoma; color:#1f2c48;">Audi California</td>
<td>&nbsp;California&nbsp;</td>
<td align="left">
A?85, bay Area, Phase 1, <br>
California<br>
California
- 6554655
</td>
<td align="right">
<br>4747744747<br>108388383
</td>
<td align="center">
info<!-- >@_ -->@<!-- >@_ -->audiCal<!-- >@_ -->.<!-- >@_ -->net
</td>
<td align="right">
&nbsp;
</td>
</tr></tbody>
</table>

I am using beautifulsoup to parse this, but now I got into problem while fetching data from last four <td>. Whenever I read their values using .string property, I get None as value. I guess this is because they have <br> tags. I want last four <td> data that has address, phone no., email_id and fax. Instead of .string what should I use to get all those data?

like image 946
Anshul Avatar asked Oct 08 '22 20:10

Anshul


1 Answers

You can use .text for getting the text.

Edit:

Another option may be getting every element using .contents and joining them as necessary.

like image 137
Sufian Latif Avatar answered Oct 12 '22 10:10

Sufian Latif