2110 views|1 replies

16

Posts

0

Resources
The OP
 

Python reverses HTML escape characters [Copy link]

 
What are escape characters

In 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 unescape

There 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. 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. 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. 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.

  1. [/font][/color][/p]1 2 3 >>> from xml.sax.saxutils import unescape >>> unescape('param=p1m=p2') 'param=p1m=p2'
复制代码

Latest reply

Very useful foundation  Details Published on 2018-2-27 23:24
 
 

1903

Posts

0

Resources
2
 
Very useful foundation
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list