有没有一种标准的方法(最好是符合Python风格的),可以将 &#xxxx;
符号转换为正确的Unicode字符串?
例如:
מפגשי
Should be converted to:
מפגשי
可以使用字符串操作轻松完成,但我想知道是否有标准库可用。
有没有一种标准的方法(最好是符合Python风格的),可以将 &#xxxx;
符号转换为正确的Unicode字符串?
例如:
מפגשי
Should be converted to:
מפגשי
>>> from HTMLParser import HTMLParser
>>> h = HTMLParser()
>>> s = "מפגשי"
>>> print h.unescape(s)
מפגשי
这也是Python的标准库的一部分。
然而,如果你使用的是Python3,你需要从html.parser
这个模块导入:
>>> from html.parser import HTMLParser
>>> h = HTMLParser()
>>> s = 'מפגשי'
>>> print(h.unescape(s))
מפגשי
unescape
似乎是内部且未记录的。是否有“官方”的方法? - georg