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')
>>> soup2
[
<option value="ufs_munic"> Por Município </option>,
<option value="ext_paises"> Por País </option>,
...
]
I’d like to get the quoted values after option value= in each tag.
For example:
ufs_munic
ext_paises
5
6
7
8
9
...
Using a list comprehension, you can get all the values from the options using the
getmethod:You can even pass a default value if the option has no option defined: