python3Unicode和字符实体转中文
Unicode转中文
如果type(text) is bytes
1 | text.decode('unicode_escape') |
如果type(text) is str
1 | text.encode('latin-1').decode('unicode_escape') |
字符实体转中文
1 | import html |
错误
1 | from html.parser import HTMLParser |
DeprecationWarning: The unescape method is deprecated and will be removed in 3.5, use html.unescape() instead.
原因:python3.4以后已经弃用
解决: 用 html 模块中的 unescape 方法
1 | import html |