Beautiful soup tag attributes - Dictionary?
clp at rebertia.com
Mon Dec 1 06:04:44 CET 2008
On Sun, Nov 30, 2008 at 8:51 PM, killsto <kiliansto at gmail.com> 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 #slicing the list to get individual item
secondPTag = tags
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
> Any ideas?
> Reference: http://www.crummy.com/software/BeautifulSoup/documentation.html#The%20attributes%20of%20Tags
More information about the Python-list