Beautifulsoup多类别选择器 [英] Beautifulsoup multiple class selector
本文介绍了Beautifulsoup多类别选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想选择所有具有A和B的div作为类属性.
I want to select all the divs which have BOTH A and B as class attributes.
以下选择
soup.findAll('div', class_=['A', 'B'])
但是
选择所有在类属性中具有A或B的div.类可以按任意顺序具有许多其他属性(C,D等),但是我只想选择同时具有A和B的那些属性.
however selects all the divs which have EITHER A or B in their class attributes. Classes may have many other attributes (C, D, etc) in any order, but I want to select only those ones that have both A and B.
推荐答案
使用css selectors
代替:
soup.select('div.A.B')
这篇关于Beautifulsoup多类别选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文