在Python 2.6中用相应的utf-8字符替换html实体 [英] Replace html entities with the corresponding utf-8 characters in Python 2.6
本文介绍了在Python 2.6中用相应的utf-8字符替换html实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的html文本:
I have a html text like this:
<xml ... >
,我想将其转换为可读的内容:
and I want to convert it to something readable:
<xml ...>
在Python中有任何简单(快速)的方法吗?
Any easy (and fast) way to do it in Python?
推荐答案
Python 2.7
HTMLParser
的官方文档: Python 2.7
>>> import HTMLParser
>>> pars = HTMLParser.HTMLParser()
>>> pars.unescape('© €')
u'\xa9 \u20ac'
>>> print _
© €
Python 3
HTMLParser
的官方文档: Python 3 >
Python 3
Official documentation for HTMLParser
: Python 3
>>> from html.parser import HTMLParser
>>> pars = HTMLParser()
>>> pars.unescape('© €')
© €
这篇关于在Python 2.6中用相应的utf-8字符替换html实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文