Beautifulsoup Multiple Class Selector


Answer :

Use css selectors instead:

soup.select('div.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) 

table = soup.find_all("tr",class_=["odd","even"]) 

Try this way! Make sure you are using proper structure of those quotes and braces. It confused me.


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?