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\'])
You can use CSS selectors instead, which is probably the best solution here.
soup.select("div.classname1.classname2")
You could also use a function.
def interesting_tags(tag):
if tag.name == "div":
classes = tag.get("class", [])
return "A" in classes and "B" in classes
soup.find_all(interesting_tags)