I'm struggling to have queries in BS with multiple conditions of the type AND or OR. From what I read I have to use lambda. As an example, I'm looking for tags that match either "span", {"class":"green"} or tag.name == "h1" on the page http://www.pythonscraping.com/pages/warandpeace.html
I manage to get them separately using the lambda syntax:
bsObj.findAll(lambda tag: tag.name == "h1")
will return h1
bsObj.findAll(lambda tag: tag.name == "span", {"class":"green"})
wil return span green
Or I can get all "span" tags and "h1" :
bsObj.findAll(lambda tag: tag.name == "span" or tag.name == "h1")
return span green and red as well as h1
But I don't manage to get the span of class green or h1, as the following code does not provide the right result :
bsObj.findAll(lambda tag: tag.name == "span", {"class":"green"} or tag.name == "h1")
Can please someone explain me the right way to do it in one query ? Goal here is not only to get the result but rather understand the syntax. Thanks !
(using Python 3.4)
PS : I think this issue is different from the the one here: BeautifulSoup findAll() given multiple classes? as well as a variation of Python BeautifulSoup give multiple tags to findAll (as we want a specific attribute)