【发布时间】:2015-01-01 09:50:32
【问题描述】:
这是我的 HTML:
<div class="left_panel">
<h4>Header1</h4>
block of text that I want.
<br />
<br />
another block of text that I want.
<br />
<br />
still more text that I want.
<br />
<br />
<p> </p>
<h4>Header2</h4>
文本块的数量是可变的,Header1是一致的,Header2不是。
我使用以下代码成功提取了第一块文本:
def get_summary (soup):
raw = soup.find('div',{"class":"left_panel"})
for h4 in raw.findAllNext('h4'):
following = h4.nextSibling
return following
但是我需要位于两个 h4 标记之间的所有项目,我希望使用 h4.nextSiblings 可以解决这个问题,但由于某种原因返回以下错误:
TypeError: 'NoneType' object is not callable
我一直在尝试对此答案的变体:Find next siblings until a certain one using beautifulsoup,但缺少前导标签让我感到困惑。
【问题讨论】:
标签: python beautifulsoup