python中的HTML字符串解码
如何在python中解码此字符串python中的HTML字符串解码,python,string,python-2.7,decode,Python,String,Python 2.7,Decode,如何在python中解码此字符串 title = 'Fast & Furious 6' 要获得: Fast & Furious 6 谢谢大家! 使用此代码,您可以从ascii演示文稿中获得字符符号 title = '
title = 'Fast & Furious 6'
要获得:
Fast & Furious 6
谢谢大家! 使用此代码,您可以从ascii演示文稿中获得字符符号
title = 'Fast & Furious 6'
title = title[:-1]
substring=[x.strip() for x in title.split(';')]
titleFinal = ''
for ch in substring:
newstr = ch.replace("&#", "")
titleFinal+=chr(int(newstr))
print(titleFinal)
只需使用内置的
html
模块:
import html
decoded_title = html.unescape(title))
因为字符串由HTML安全序列(数字字符引用)组成。这是HTML编码的,而不是XML。