Extracting an attribute value with beautifulsoup

Posted by Barnabe on Stack Overflow See other posts from Stack Overflow or by Barnabe
Published on 2010-04-10T06:53:01Z Indexed on 2010/04/10 7:03 UTC
Read the original article Hit count: 616

Filed under:
|
|
|

I am trying to extract the content of a single "value" attribute in a specific "input" tag on a webpage. I use the following code:

import urllib
f = urllib.urlopen("http://58.68.130.147")
s = f.read()
f.close()

from BeautifulSoup import BeautifulStoneSoup
soup = BeautifulStoneSoup(s)

inputTag = soup.findAll(attrs={"name" : "stainfo"})

output = inputTag['value']

print str(output)

I get a TypeError: list indices must be integers, not str

even though from the Beautifulsoup documentation i understand that strings should not be a problem here... but i a no specialist and i may have misunderstood.

Any suggestion is greatly appreciated! Thanks in advance.

© Stack Overflow or respective owner

Related posts about python

Related posts about beautifulsoup