class='something' as kwarg

Marc Christiansen usenet at solar-empire.de
Sat Nov 17 08:39:39 EST 2007


Vladimir Rusinov <vladimir at greenmice.info> 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
  from BeautifulSoup import BeautifulSoup as BSoup
> 
> ...
> 
> soup = BSoup(page)
> for div in soup.findAll('div', class='g'):
  for div in soup.findAll('div', attrs={'class':'g'}):
>    <do something>
> 
> But how can I use `class` as kwarg name?

You can't. But you can use the attrs argument (see above).

HTH
  Marc



More information about the Python-list mailing list