在一个BS find_all

时间:2019-10-17 19:56:41

标签: python html beautifulsoup

是否可以通过beautifulSoup在一个“ soup.find_all”中提取两个HTML div标签? div被重复称为“事件奇数”,“事件偶数”,我想遍历它们全部

网页代码:

<div class="event odd">
    <div class="featured-image">
        <a href="https://dme-promotions.com/event/gloryhammer-beast-in-black-wind-rose/" style="background-image:url('https://dme-promotions.com/wp-content/uploads/2019/02/Gloryhammer-600x395.jpg');"></a>
    </div>

<div class="event even">..</div> == $0
<div class="event odd">..</div> == $0
<div class="event even">..</div> == $0
<div class="event odd">..</div> == $0

我的代码:

  

音乐会=汤.find_all(['div',{'class':'事件奇数'},{'class':'事件偶数}])

for concert in concerts:
    name = concert.find('a').get('href')

1 个答案:

答案 0 :(得分:1)

您可以使用{'class': 'event'}中的Bitto Bennichan's suggestion

或者,如果必须一次指定两个值,则可以在列表中传递它们:

>>> len(soup.find_all('div', {'class': ['event odd', 'event even']}))
5