I want to preserve <br>
tags as
when extracting the text content from lxml elements.
Example code:
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)
Output:
> h.text_content()
'This is a text node.This is another text node.And a child element.Another child, with two text nodes'
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…