我想在从lxml元素提取文本内容时将<br>
标记保留为\n
。
示例代码:
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'
目前没有回答
相关问题 更多 >
编程相关推荐