Python以&符号格式转换html标签

时间:2016-03-03 09:39:14

标签: python text-to-html

我的文字格式如下 & div ampersand gt; \ n&ampersand lt; div ampersand gt; & span& span> Customer ..如何将此文本转换为html即

<div>
<div>
<span>
Customer..

1 个答案:

答案 0 :(得分:1)

尝试:

import html
html_string = "ampersand lt;div ampersand gt;\n ampersand lt;div ampersand gt; ampersand lt;span ampersand gt;Customer..".replace("ampersand ", "&")
html.unescape(html_string)

如果您希望维持新行:

html.unescape(html_string.replace("\n", "<br />"))