Use BeautifulSoup to delete certain tag while keeping its content

John Nagle nagle at animats.com
Sun Sep 7 22:52:07 EDT 2008


Jackie Wang wrote:
> Dear all,
> 
> I have the following html code:
> 
> <td valign="top" headers="col1">
>  <font size="2">
>   Center Bank
>   <br />
>   Los Angeles, CA
>  </font>
> </td>
> 
> <td valign="top" headers="col1">
>  <font size="2">
>   Salisbury
> Bank and Trust Company
>   <font face="arial, helvetica" size="2" color="#0000000">
>    <br />
>    Lakeville, CT
>   </font>
>  </font>
> </td>
> 
> How should I delete the 'font' tags while keeping the content inside?

     See the BeautifulSoup documentation.  Find the font tags with findAll,
make a list, then go in and use "extract" and "replaceWith" appropriately.

				John Nagle




More information about the Python-list mailing list