[英]How to decode ascii combined with string in python
I am trying to decode and ascii which is combined with string 我正在尝试解码和结合字符串的ASCII
example 例
glbosworth
But i am not getting exact output 但是我没有得到确切的输出
'glbosworth'.decode("ascii")
output 输出
u'glbosworth'
if u remove this characters &# and try only with integers i get this 如果您删除此字符&#并仅尝试使用整数我会得到这个
>>> chr(108)
'l'
>>> chr(115)
's'
>>> chr(111)
'o'
>>> chr(114)
'r'
>>> chr(104)
'h'
expected output 预期产量
glbosworth
How can i decode this one "glbosworth" to expected output 我如何将这一个“ g&#108bo&#115w&#111&#114t&#104”解码为预期的输出
you are trying to decode html escaped string . 您正在尝试解码html转义的字符串 。 you can use the
html.unescape(s)
function to do so (on python3): 您可以使用
html.unescape(s)
函数这样做(在python3上):
import html
print(html.unescape('glbosworth'))
outputs: 输出:
'glbosworth'
on python3.6.x you can use html.unescape : 在python3.6.x上,您可以使用html.unescape :
import html print(html.unescape('glbosworth'))
on python 2.x you can use HTMLParser : 在python 2.x上,您可以使用HTMLParser :
from HTMLParser import HTMLParser h = HTMLParser() print(h.unescape('glbosworth'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.