Extracting tag information with beautifulsoup and python

Omifflef

New Member
Say I have some xml like\[code\]<item name=bread weight="5" edible="yes"><body> some blah </body><item><item name=eggs weight="5" edible="yes"><body> some blah </body><item><item name=meat weight="5" edible="yes"><body> some blah </body><item>\[/code\]I want to store the name of each item in a list using beautiful soupHere's the attempt so far:\[code\]names =list()for c in soup.findAll("item"): #get name from the tag names.append(name i got from tag)\[/code\]This method has worked perfectly for extracting text between tags.I've tried copying the methods used for extracting links \[code\]<a href="http://stackoverflow.com/questions/10521443/www.blah.com">\[/code\] but it doesn't seem to work.How would I store the name information in a list? (other lists contain the body text so for associativity reasons the indexes have to be consistent).Thanks very much
 
Back
Top