Is it possible to extract two HTML div tags in one “soup.find_all” with beautifulSoup? The divs are repeatedly called “event odd”, “event even” and i want to loop through them all
webpage code:
<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
My code:
concerts = soup.find_all([‘div’, {‘class’: ‘event odd’}, {‘class’: ‘event even’}])
for concert in concerts: name = concert.find('a').get('href')
Advertisement
Answer
You can use Bitto Bennichan’s suggestion of using {'class': 'event'}
.
Or, if you must specify two values at once, you can pass them in a list:
>>> len(soup.find_all('div', {'class': ['event odd', 'event even']})) 5