【发布时间】:2012-02-13 03:12:41
【问题描述】:
我有一个如下格式的 Html 文档。
<p> 1. Content of the paragraph <i> in italic </i> but not <b> strong </b> <a href="url">ignore</a>.</p>
我想提取段落标签的内容,包括斜体和粗体标签的内容,但不包括锚标签的内容。此外,可以忽略开头的数字。
预期的输出是: 段落内容为斜体,但不强。
最好的方法是什么?
另外,以下代码 sn-p 返回 TypeError: argument of type 'NoneType' is not iterable
soup = BSoup(page)
for p in soup.findAll('p'):
if ' ' in p.string:
print p
感谢您的建议。
【问题讨论】:
标签: python beautifulsoup html-content-extraction