朱皮特的博客 自由的飞翔

Python网页字符串的转义与反转义

2018-07-02
朱皮特
阅读量:

escape和unescape

s = 'Elements are written as "<tag>text</tag>".'
import html
print(html.escape(s))
# Elements are written as &quot;&lt;tag&gt;text&lt;/tag&gt;&quot;.

# Disable escaping of quotes
print(html.escape(s, quote=False))  
# Elements are written as "&lt;tag&gt;text&lt;/tag&gt;".

t = 'The prompt is &gt;&gt;&gt;'
print(html.unescape(t)) # The prompt is >>>

Comments

Content