📜  Python中的 html.escape()

📅  最后修改于: 2022-05-13 01:54:48.146000             🧑  作者: Mango

Python中的 html.escape()

借助html.escape()方法,我们可以通过使用html.escape()方法将特殊字符替换为带有 ascii字符的字符串,从而将 html 脚本转换为字符串。

示例 #1:
在这个例子中我们可以看到,通过使用html.escape()方法,我们可以使用该方法将 html 脚本转换为 ascii字符串。

# import html
import html
  
s = '

This is python

' # Using html.escape() method gfg = html.escape(s)    print(gfg)

输出 :

示例 #2:

# import html
import html
  
s = '

GeeksForGeeks

' # Using html.escape() method gfg = html.escape(s)    print(gfg)

输出 :