lxml要素からテキストコンテンツを抽出するときに、<br>
タグを\n
として保存します。<br>は、lxml.htmlのtext_content()またはそれと同等の改行としてどのように保存できますか?
例コード:
fragment = '<div>This is a text node.<br/>This is another text node.<br/><br/><span>And a child element.</span><span>Another child,<br> with two text nodes</span></div>'
h = lxml.html.fromstring(fragment)
出力:
> h.text_content()
'This is a text node.This is another text node.And a child element.Another child, with two text nodes'
解析後はどうなっていますか? –