I want to select all the divs which have BOTH A and B as class attributes.
The following selection
soup.findAll('div', class_=['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.
get(link) soup = BeautifulSoup(r. text) items = soup. findAll(True, {"class":["equal achievements number", "up achievements number"]}) This one is applying Roman Pekar's solution, but it returns an empty list. The same thing happens using the regular expression solution.
Use css selectors
instead:
soup.select('div.A.B')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With