Python 在beautifulsoup中合并查询

Python 在beautifulsoup中合并查询,python,beautifulsoup,Python,Beautifulsoup,我在beautifulsoup中使用的查询是否有简化(合并)的方法 table = soup.findAll("tr", {'class' : 'table-tempo-row' }) tablec = soup.findAll("tr", {'class' : 'table-tempo-row-alt' }) for i in (table + tablec): tableb = i.findAll("td") 谢谢。您可以通过: BS将tr元素与

我在beautifulsoup中使用的查询是否有简化(合并)的方法

    table  = soup.findAll("tr", {'class' : 'table-tempo-row' })
    tablec = soup.findAll("tr", {'class' : 'table-tempo-row-alt' })

    for i in (table + tablec):
        tableb = i.findAll("td")
谢谢。

您可以通过:

BS将
tr
元素与任一类匹配


对于更复杂的情况,可以传入正则表达式或函数(接受元素并返回布尔值)。

这非常简洁,对我帮助很大。非常感谢。
table = soup.findAll("tr", {'class' : ['table-tempo-row', 'table-tempo-row-alt'] })
tablec = soup.findAll("tr", {'class' : ('table-tempo-row-alt' ,'table-tempo-row')})