class='something' as kwarg

Peter Otten __peter__ at web.de
Sat Nov 17 08:43:24 EST 2007


Vladimir Rusinov wrote:

> I'm using beautiful soup html parser, and I need to get all '<div
> class=g>...</div>' tags.
> It can be done by:
> 
> import BeautifulSoup as BSoup
> 
> ...
> 
> soup = BSoup(page)
> for div in soup.findAll('div', class='g'):
>     <do something>
> 
> But how can I use `class` as kwarg name?

# hack
findAll("div", **{"class": "g"})

# official workaround
findAll("div", attrs={"class": "g"})

Peter



More information about the Python-list mailing list