python中的HTML字符串解码

2024-04-24 20:15:54 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在python中解码这个字符串?你知道吗

title = 'Fast & Furious 6'

要获得:

Fast & Furious 6

谢谢你!你知道吗


Tags: 字符串title解码fastfurious
2条回答

用这个代码你可以从ascii中得到char符号。你知道吗

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安全序列(数字字符引用)组成。你知道吗

相关问题 更多 >