What are escape charactersIn HTML, characters such as <, >, and & have special meanings (< and > are used in tags, and & is used for escape). They cannot be used directly in HTML code. If you want to display these symbols in a web page, you need to use HTML's escape sequence. For example, the escape character of < is <. When the browser renders an HTML page, it automatically replaces the escape sequence with real characters.
The escape sequence consists of three parts: the first part is an & symbol, the second part is the entity name, and the third part is a semicolon. For example, to display a less than sign (<), you can write <.
Display character description escape character
< less than<
Space
< less than<
> Greater than>
& & symbol&
" Double quotes"
Copyright
[p=26, null, Python escape string unescape
Registered Trademark
Python escape string unescapeThere are many ways to handle escape strings in Python, and the processing methods are different in py2 and py3. In python2, the module for unescape is HTMLParser.
- 1 2 3 4 # Python2 import HTMLParser >>> HTMLParser().unescape('param=p1m=p2') 'param=p1m=p2'
复制代码
Python3 HTMLParser module has been migrated to html.parser
- 1 2 3 4 # Python3 >>> from html.parser import HTMLParser >>> HTMLParser().unescape('param=p1m=p2') [p=26, null, unescape('param=p1m=p2') [p=26, null, left][color=rgb(51, 51, 51)][font=-apple-system, BlinkMacSystemFont, "]'param=p1m=p2'
复制代码In versions later than Python 3.4, the unescape method was added to the html module.
- 1 2 3 4 # Python 3.4 >>> import html >>> html.unescape('param=p1m=p2') [p=26, null, left][color=rgb(51, 51, 51)][font=-apple-system, BlinkMacSystemFont, "]'param=p1m=p2'
复制代码The last method is recommended because the HTMLParser.unescape method has been deprecated in Python 3.4 and is not recommended for use, which means that it will be completely removed in subsequent versions.
In addition, the xml sax module also has functions that support unescape.- [/font][/color][/p]1 2 3 >>> from xml.sax.saxutils import unescape >>> unescape('param=p1m=p2') 'param=p1m=p2'
复制代码