Get Value Attribute For Each Tag Found Using Tag.find_all()
I've generated a list with all tags of my HTML file called 'option'. But I can't get the values inside the tag. This is my code and data: >>> soup2 = soup.findAll('option'
Solution 1:
Using a list comprehension, you can get all the values from the options using the get
method:
>>> soup2 = [option.get('value') for option in soup.findAll('option')]
>>> soup2
['ufs_munic', 'ext_paises', '5', '6', '7', '8', '9', ...]
You can even pass a default value if the option has no option defined:
option.get('value', 'There is no value!')
Solution 2:
>>>for item in soup2:...print item['value']
Post a Comment for "Get Value Attribute For Each Tag Found Using Tag.find_all()"