2016-03-03 120 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 />"))