2024-04-25 07:17:53 发布
网友
我在元素对象的.text中有这个
e = ET.Element('p') e.text = "hello <br> world" e.write("a.html")
似乎不像预期的那样有效。 它将天使方括号转换为<; 有办法解决这个问题吗?在
<
您可以使用tail属性,我还没有测试过它,但它应该可以像您预期的那样工作:
tail
e = ET.Element('p') # you set the text to hello first e.text = "hello " # and you set a subelement with br, which is what you want br = ET.SubElement(e, 'br') # then using tail to append the text after br br.tail = ' world' ...
希望这有帮助。在
您可以使用
tail
属性,我还没有测试过它,但它应该可以像您预期的那样工作:希望这有帮助。在
相关问题 更多 >
编程相关推荐