I am trying to decode and ascii which is combined with string
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
you are trying to decode html escaped string . you can use the html.unescape(s)
function to do so (on python3):
import html
print(html.unescape('glbosworth'))
outputs:
'glbosworth'
take a look at this so answer for more info
on python3.6.x you can use html.unescape :
import html print(html.unescape('glbosworth'))
on python 2.x you can use HTMLParser :
from HTMLParser import HTMLParser h = HTMLParser() print(h.unescape('glbosworth'))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.