【发布时间】:2019-10-17 19:56:41
【问题描述】:
是否可以使用 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
我的代码:
concerts = soup.find_all(['div', {'class': 'event odd'}, {'class': 'event even'}])
for concert in concerts:
name = concert.find('a').get('href')
【问题讨论】:
-
为什么不简单地获取所有带有“事件”类的 div?
-
@Bitto Bennichan 工作完美,谢谢。
标签: python html beautifulsoup