我想用python提取html中的段落。我使用了 lxml 模块,但它并不完全符合我的要求。
print html.parse(url).xpath('//p')[1].text_content()
<span id="midArticle_1"></span><p>Here is the First Paragraph.</p><span id="midArticle_2"></span><p>Here is the second Paragraph.</p><span id="midArticle_3"></span><p>Paragraph Three."</p>
我应该补充一点,在不同的页面中,我有不同数量的段落,所以想制作一个列表,然后将段落放入其中。
最佳答案
print html.parse(url).xpath('//p/text()')
输出
['Here is the First Paragraph.', 'Here is the second Paragraph.',
'Paragraph Three."']
关于python - 使用lxml在python中提取段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5034351/