开发者

extracting paragraph in python using lxml

开发者 https://www.devze.com 2023-02-11 12:57 出处:网络
I would like to extract paragraphs in html by python. I u开发者_如何学编程sed lxml module but it doesn\'t do exactly what I am looking for.

I would like to extract paragraphs in html by python. I u开发者_如何学编程sed 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.


print html.parse(url).xpath('//p/text()')

Output

['Here is the First Paragraph.', 'Here is the second Paragraph.', 
 'Paragraph Three."']
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号