我正在尝试input从页面获取标签,但我不想返回任何带有 type 属性的hidden.
我可以得到所有hidden字段,soup.find_all('input', attrs={'type': 'hidden'})但你不能用attrs!={'type': 'hidden'}.
是否有一种简单的单行方式来获取与给定属性的条件不匹配的所有标签?
我正在尝试input从页面获取标签,但我不想返回任何带有 type 属性的hidden.
我可以得到所有hidden字段,soup.find_all('input', attrs={'type': 'hidden'})但你不能用attrs!={'type': 'hidden'}.
是否有一种简单的单行方式来获取与给定属性的条件不匹配的所有标签?
您必须使用函数 match:
def input_not_type_hidden(tag):
return tag.name == 'input' and tag.get('type') != 'hidden'
soup.find_all(input_not_type_hidden)