Voglio conservare <br>
tag come \n
quando si estrae il contenuto del testo da elementi lxml.Come posso conservare <br> come nuove righe con lxml.html TEXT_CONTENT() o equivalente?
codice Esempio:
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)
uscita:
> h.text_content()
'This is a text node.This is another text node.And a child element.Another child, with two text nodes'
Che aspetto ha dopo l'analisi? –