2016-03-03 62 views
0

我有以下格式的文本 < div&> \ n<< div&符号LT;跨度符号GT;客户..我如何转换这个文本到HTML即Python按照&符号转换html标记

<div> 
<div> 
<span> 
Customer.. 
+0

请参阅[htmlunescape](https://wiki.python.org/moin/EscapingHtml) – JustMe

+2

使用“和号格式”编写某些内容称为转义,因此您实际所寻找的是如何使用HTML格式的Unescape HTML, e:http://stackoverflow.com/questions/2360598/how-do-i-unescape-html-entities-in-a-string-in-python-3-1 –

+0

谢谢@DanielHepper。我不知道 – Nitin

回答

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 />"))