python - Python 的美丽汤 - 返回所有复选框?
问题描述
我有几个网站需要与复选框进行交互。
一些 html 看起来像这样:
<input type="checkbox" />
<span>Red</span>
</label>
</p>
<p>
<label>
<input type="checkbox" checked="checked" />
<span>Yellow</span>
还有一些具有属性“值”。我需要一种方法来返回状态并在这两种情况下与复选框进行交互。但是下面的代码不起作用,因为它会查找属性值。一般有没有办法处理复选框?
def GetCheckboxes(website):
checkboxes = website.find('input', {"type": "checkbox"})["value"]
return checkboxes
def GetWebsite(url):
result = requests.get(url)
src = result.content
soup = BeautifulSoup(src, 'lxml')
return soup
website = GetWebsite('https://materializecss.com/checkboxes.html')
print (GetCheckboxes(website))
解决方案
推荐阅读
- javascript - Angular 从服务方法()调用一个数组到我的主要组件;
- python - 如何在 Python 中从 txt 文件中读取土耳其语字符?
- c++ - 在类构造函数中传递对外部函数的引用
- asp.net - .Net Session for load balanced Servers
- php - 未知列....在“where 子句”中,当列存在并且无法解决此问题时 - Codeigniter
- azure - 如何在 Terraform 的订阅中获取现有 Azure 资源?
- c# - 用标签隐藏克隆游戏对象
- reactjs - 如何从另一个功能性反应组件调用功能性反应组件的方法?
- json - 如何使用 JSON Schema 验证承诺对象键的存在?
- javascript - 单击按钮或链接以设置为默认选项,使用