HTML Unescape没有取消对特殊字符的捕获



我的程序不会取消捕获引号的HTML特殊字符,我不知道为什么。它仍然在终端中显示特殊字符。

例如:'In the comic book "Archie"

import requests
import html
API_URL = "https://opentdb.com/api.php"
parameters = {
"amount": 10,
"type": "boolean"
}
response = requests.get(API_URL, params=parameters)
data = html.unescape(response.json())
unescaped_data = data["results"]
print(f"UNESCAPED DATA: {unescaped_data}") # THIS IS NOT WORKING

由于response.json()返回的是JSON对象(即dict(而不是字符串,因此不会取消对结果的映射。如果您愿意,您可以使用html.unescape(response.text)取消捕获响应字符串,但这将留下无效的JSON,例如:"question":""Windows NT" is a monolithic kernel.",(注意附加的引号(。因此,转义是有原因的,您必须只对那些真正需要的部分进行取消转义,即JSON对象的字符串组件。

当我将response.json()更改为response.text时,它工作于

data = html.unescape(response.text)

最新更新