我正在尝试获取input
页面中的标签,但我不想返回任何带有 type 属性 hidden
的标签.
我可以获得所有hidden
包含 soup.find_all('input', attrs={'type': 'hidden'})
的字段但你不能仅仅用 attrs!={'type': 'hidden'}
来否定这一点.
是否有一种简单的单行方法来获取所有不与给定属性上的条件匹配的标签?
最佳答案
您必须使用 function match :
def input_not_type_hidden(tag):
return tag.name == 'input' and tag.get('type') != 'hidden'
soup.find_all(input_not_type_hidden)
关于python - BeautifulSoup 中不满足条件的标签可以返回吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17783813/