使用lxml在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>
我应该补充一点,在不同的页面中,我有不同数量的段落,所以想制作一个列表,然后将段落放入其中。
I would like to extract paragraphs in html by python. I used lxml module but it doesn't do exactly what I am looking for.
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>
I should add that, in different pages I have different number of paragraph, so would like to make a list and put paragraph into it after that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输出
Output