Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中的HTML字符串解码_Python_String_Python 2.7_Decode - Fatal编程技术网

python中的HTML字符串解码

python中的HTML字符串解码,python,string,python-2.7,decode,Python,String,Python 2.7,Decode,如何在python中解码此字符串 title = 'Fast & Furious 6' 要获得: Fast & Furious 6 谢谢大家! 使用此代码,您可以从ascii演示文稿中获得字符符号 title = '

如何在python中解码此字符串

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。