2

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>

追加する必要があります。ページごとに段落数が異なるので、リストを作成して、その後に段落を入れたいと思います。

4

1 に答える 1

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

出力

['Here is the First Paragraph.', 'Here is the second Paragraph.', 
 'Paragraph Three."']
于 2011-02-17T20:52:48.287 に答える