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 选择器
:
soup.select('div.A.B')
这篇关于Beautifulsoup 多类选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文