美文网首页
python html.escape()

python html.escape()

作者: 2023开始学 | 来源:发表于2023-04-24 20:14 被阅读0次

def escape(s, quote=True):

"""

Replace special characters "&", "<" and ">" to HTML-safe sequences.

If the optional flag quote is true (the default), the quotation mark

characters, both double quote (") and single quote (') characters are also

translated.

"""

    s = s.replace("&","&amp;")# Must be done first!

    s = s.replace("<","&lt;")

s = s.replace(">","&gt;")

if quote:

s = s.replace('"',"&quot;")

s = s.replace('\'',"&#x27;")

return s

相关文章

网友评论

      本文标题:python html.escape()

      本文链接:https://www.haomeiwen.com/subject/dpcaartx.html