原地址:https://stackoverflow.com/questions/275174/how-do-i-perform-html-decoding-encoding-using-python-django

 

HTML Escape  

 

try:
    from html import escape  # python 3.x
except ImportError:
    from cgi import escape  # python 2.x

print(escape("<"))

 HTML Unescape

try:
    from html import unescape  # python 3.4+
except ImportError:
    try:
        from html.parser import HTMLParser  # python 3.x (<3.4)
    except ImportError:
        from HTMLParser import HTMLParser  # python 2.x
    unescape = HTMLParser().unescape

print(unescape(">"))

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2021-07-03
  • 2021-06-19
  • 2022-12-23
  • 2021-06-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
相关资源
相似解决方案