python - Get the selected option using BeautifulSoup -


from bs4 import beautifulsoup soup = beautifulsoup( '''<select> <option value="1">one</option> <option value="2" selected>two</option> <option value="3">three</option> <option value="4">four</option> <option value="5">five</option> </select>''' )  print( soup.findall('option', selected=true) ) 

the output is:

[] 

i trying string of selected option in example above. cannot correct option if "selected" not assigned anything, not have set true.

from bs4 import beautifulsoup  soup = beautifulsoup( '''<select> <option value="1">one</option> <option value="2" selected=''>two</option> <option value="3">three</option> <option value="4">four</option> <option value="5">five</option> </select>''' )  print( soup.findall('option', selected=true) ) 

the output is:

[<option selected="" value="2">two</option>] 

since reading html file, don't have control on part. there way work around? using beahutifulsoup 4.1.3 , python 3.3.0


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -