By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

class='something' as kwarg

P: n/a
Hello!

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?

--
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
Nov 17 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
But how can I use `class` as kwarg name?

soup.findAll('div', **{'class':'g'})

Nov 17 '07 #2

P: n/a
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
Nov 17 '07 #3

P: n/a
Vladimir Rusinov <vl******@greenmice.infowrote:
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
Nov 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.