[Tutor] Using Beautiful Soup to find an HTML element by its class attribute

Sithembewena Lloyd Dube zebra05 at gmail.com
Mon May 31 02:01:48 CEST 2010


Thanks all, I found the solution: using the attributes dictionary as
follows:

weather_row = soup.findAll('tr', { "class" : "rs1" })

Many thanks.

On Mon, May 31, 2010 at 1:32 AM, Sithembewena Lloyd Dube
<zebra05 at gmail.com>wrote:

> Hi everyone,
>
> I am using urllib to scrape an HTML page, and creating an instance of
> BeautifulSoup as follows:
> *
> *from BeautifulSoup import BeautifulSoup
> import re, urllib
>
> doc = urllib.urlopen(my_url).read()
> soup = BeautifulSoup(''.join(doc))
>
> #print soup.prettify()
> weather_row = soup.findAll('tr', class="rs1")
> print weather_row
>
> The call to soup.findAll is failing because "class" is a reserved keyword
> in Python. Using BeautifulSoup, how can I find a specific table row whose
> only identifying attribute is its CSS class?
>
> Thanks.
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>



-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100531/c9bbf668/attachment.html>


More information about the Tutor mailing list