Beautiful soup tag attributes - Dictionary?

Chris Rebert clp at
Mon Dec 1 06:04:44 CET 2008

On Sun, Nov 30, 2008 at 8:51 PM, killsto <kiliansto at> wrote:
> The documentation says I can find attributes of tags by using it as a
> dictionary. Ex:
> product = p.findAll('dd')

.findAll() produces a *list* of tags

The example in the docs is:
firstPTag, secondPTag = soup.findAll('p')

which is using *tuple unpacking*, so it's equivalent to:

tags = soup.findAll('p')
firstPTag = tags[0] #slicing the list to get individual item
secondPTag = tags[1]

So, you either need to use .find() instead of .findAll(), or treat the
result of .findAll() correctly as a list of tags.

Follow the path of the Iguana...

> print product['id']
> However, when I try that python thinks I am slicing it. When I print
> product, it works but is a list. I am pretty sure I have the latest
> version.
> Any ideas?
> Reference:
> --

More information about the Python-list mailing list