Python中的 html.escape()
借助html.escape()
方法,我们可以通过使用html.escape()
方法将特殊字符替换为带有 ascii字符的字符串,从而将 html 脚本转换为字符串。
Syntax : html.escape(String)
Return : Return a string of ascii character script from html.
示例 #1:
在这个例子中我们可以看到,通过使用html.escape()
方法,我们可以使用该方法将 html 脚本转换为 ascii字符串。
# import html
import html
s = 'This is python
'
# Using html.escape() method
gfg = html.escape(s)
print(gfg)
输出 :
This is python
示例 #2:
# import html
import html
s = 'GeeksForGeeks
'
# Using html.escape() method
gfg = html.escape(s)
print(gfg)
输出 :