python-parser running Beautiful Soup needs to be reviewed

Peter Pearson ppearson at nowhere.invalid
Sat Dec 11 17:13:09 EST 2010


On Sat, 11 Dec 2010 22:38:43 +0100, Stef Mientki wrote:
[snip]
> So the simplest solution I came up with:
>
> Text = """
><table class="bp_ergebnis_tab_info">
>     <tr>
>             <td>
>                      This is a sample text
>             </td>
>
>             <td>
>                      This is the second sample text
>             </td>
>     </tr>
></table>
> """
> Content = BeautifulSoup ( Text )
> print Content.find('td').contents[0].strip()
>>>> This is a sample text
>
> And now I wonder how to get the next contents !!

Here's a suggestion:

peter at eleodes:~$ python
Python 2.5.2 (r252:60911, Jul 22 2009, 15:35:03) 
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from BeautifulSoup import BeautifulSoup
>>> Text = """
... <table class="bp_ergebnis_tab_info">
...     <tr>
...             <td>
...                      This is a sample text
...             </td>
... 
...             <td>
...                      This is the second sample text
...             </td>
...     </tr>
... </table>
... """
>>> Content = BeautifulSoup ( Text )
>>> for xx in Content.findAll('td'):
...   print xx.contents[0].strip()
... 
This is a sample text
This is the second sample text
>>> 

-- 
To email me, substitute nowhere->spamcop, invalid->net.



More information about the Python-list mailing list