使用lxm在python中提取段落

2024-10-01 04:50:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用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>

我要补充的是,在不同的页数我有不同的段落数,所以想列一个列表,然后把段落放进去。在


Tags: 模块theidurlhereparseishtml