【问题标题】:Python convert html tags in ampersand formatPython将html标签转换为&符号格式
【发布时间】:2016-03-03 18:15:12
【问题描述】:

我有以下格式的文本 & lt;div & gt;\n & lt;div > & lt;span & gt;Customer.. 我怎样才能将此文本转换为 html 即

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

【问题讨论】:

标签: python text-to-html


【解决方案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 />"))

【讨论】:

    猜你喜欢
    • 2015-11-20
    • 1970-01-01
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    相关资源
    最近更新 更多