python处理字符串为html_用Python字符串解码HTML实体?

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-24 07:13   19   0

手掌心

Python 3.4+HTMLParser.unescape不受欢迎,而且应该在3.5中被移除虽然它被错误地留下了。它很快就会从语言中删除。相反,使用html.unescape():import htmlprint(html.unescape('682m'))看见https:/docs.python.org/3/Library/html.html#html.unawayPython 2.6-3.3您可以使用标准库中的HTML解析器:>>> try:... # Python 2.6-2.7 ... from HTMLParser import HTMLParser... except ImportError:... # Python 3...

from html.parser import HTMLParser... >>> h = HTMLParser()>>> print(h.unescape('682m'))682m看见http:/docs.python.org/2/Library/htmlparser.html您还可以使用six兼容性库以简化导入:>>> from six.moves.html_parser import HTMLParser>>> h = HTMLParser()>>> print(h.unescape('682m'))682m

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP