【发布时间】:2017-01-19 01:57:00
【问题描述】:
我一直在尝试使用 find_all() 方法选择具有下一个元素为 p 的标签 h1,但我得到的是空列表。这是我的代码,
def has_h1_followedby_p(tag):
return tag.name == 'h1' and tag.next_siblings.name == 'p'
soup = BeautifulSoup(open(filepath), 'html.parser')
h1_tags = soup.find_all(has_h1_followedby_p)
我想知道这种情况到底出了什么问题,因为它看起来很简单。我将非常感谢您提出任何建议。
【问题讨论】: