Python:如何选中html广播框?
我不熟悉Python和 我想搜索是否选中了收音机框。 这是我的HTML代码Python:如何选中html广播框?,python,html,Python,Html,我不熟悉Python和 我想搜索是否选中了收音机框。 这是我的HTML代码 <input type="radio" name="radio1" value="1" checked> <input type="radio" name="radio2" value="2"> <input type="radio" name="radio3" value="3" checked> 试用has\u attr: from bs4 import BeautifulSo
<input type="radio" name="radio1" value="1" checked>
<input type="radio" name="radio2" value="2">
<input type="radio" name="radio3" value="3" checked>
试用
has\u attr
:
from bs4 import BeautifulSoup
div_test = """
<input type="radio" name="radio1" value="1" checked/>
<input type="radio" name="radio2" value="2"/>
<input type="radio" name="radio3" value="3" checked/>
"""
soup = BeautifulSoup(div_test,'html.parser')
print soup.find('input',attrs={'name':'radio1'}).has_attr('checked')
print soup.find('input',attrs={'name':'radio2'}).has_attr('checked')
print soup.find('input',attrs={'name':'radio3'}).has_attr('checked')
:检查这个
from bs4 import BeautifulSoup
div_test = """
<input type="radio" name="radio1" value="1" checked/>
<input type="radio" name="radio2" value="2"/>
<input type="radio" name="radio3" value="3" checked/>
"""
soup = BeautifulSoup(div_test,'html.parser')
print soup.find('input',attrs={'name':'radio1'}).has_attr('checked')
print soup.find('input',attrs={'name':'radio2'}).has_attr('checked')
print soup.find('input',attrs={'name':'radio3'}).has_attr('checked')
True
False
True