借助html.unescape()
方法,我們可以使用以下方式將ascii字符替換為特殊字符,從而將ascii字符串轉換為html腳本:html.escape()
方法。
用法:html.unescape(String)
返回:Return a html script.
範例1:
在這個例子中,我們可以通過使用html.unescape()
方法,我們可以使用此方法將ascii字符串轉換為html腳本。
# import html
import html
s = '<html><head></head><body><h1>This is python</h1></body></html>'
temp = html.escape(s)
# Using html.unescape() method
gfg = html.unescape(temp)
print(gfg)
輸出:
This is python
範例2:
# import html
import html
s = '<html><head></head><body><h1>GeeksForGeeks</h1></body></html>'
temp = html.escape(s)
# Using html.unescape() method
gfg = html.unescape(temp)
print(gfg)
輸出:
GeeksForGeeks
相關用法
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 html.unescape() in python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。