这是什么 "jQuery110..." 得到响应,我该如何处理它?

What is this "jQuery110..." get response, and how do I process it?

我正在使用获取请求来获取此响应:

jQuery110206339660961653864_1654368471800([{"specid":"2972178","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr.","score":"230.12%"},{"specid":"2972179","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. SP","score":"230.12%"},{"specid":"2972180","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Ssp","score":"230.12%"},{"specid":"3122355","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Yellow","score":"230.12%"},{"specid":"3202267","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Gold","score":"230.12%"},{"specid":"3382322","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Clear","score":"230.12%"},{"specid":"3486832","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Black","score":"230.12%"},{"specid":"3486118","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Purple","score":"230.12%"},{"specid":"6575615","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. SP-5x7","score":"230.12%"},{"specid":"3182606","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Rainbow Foil","score":"206.51%"},{"specid":"3290898","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Memorial Day Camo","score":"206.51%"},{"specid":"3382730","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Gold Foil","score":"206.51%"},{"specid":"3480943","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Mother\u0027s Day Pink","score":"206.51%"},{"specid":"3481849","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Father\u0027s Day Blue","score":"206.51%"},{"specid":"3483733","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Independence Day","score":"206.51%"},{"specid":"3633310","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Vintage Stock","score":"206.51%"},{"specid":"3649859","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Advanced Stat","score":"206.51%"},{"specid":"3765561","sport":"Baseball Cards","description":"2020 Topps Chrome Sapphire Edition 168 Fernando Tatis Jr.","score":"206.51%"},{"specid":"3786644","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Retail Foilboard","score":"206.51%"},{"specid":"3787457","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Hobby Foilboard","score":"206.51%"},{"specid":"3789403","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Gold Stars","score":"206.51%"},{"specid":"3790179","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Blue","score":"206.51%"},{"specid":"3790919","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Orange","score":"206.51%"},{"specid":"3792370","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Foilfractor 1/1","score":"206.51%"},{"specid":"3791656","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. 1st Edition","score":"206.51%"}]);

我在大括号中看到 python 字典和 key:value 对,但我从未见过像这样的多个字典的响应。我曾尝试将其视为 json 数据,因为这就是 google chrome 开发工具所说的响应是“application/json; charset=utf-8”。

我正在寻找的是将前五个花括号放入一本字典中,但我什至不知道如何定义一个自己的字典。任何帮助将不胜感激。

要将数据解析为 Python 字典,您可以使用 re/json 模块:

import re
import json

s = 'jQuery110206339660961653864_1654368471800([{"specid":"2972178","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr.","score":"230.12%"},{"specid":"2972179","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. SP","score":"230.12%"},{"specid":"2972180","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Ssp","score":"230.12%"},{"specid":"3122355","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Yellow","score":"230.12%"},{"specid":"3202267","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Gold","score":"230.12%"},{"specid":"3382322","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Clear","score":"230.12%"},{"specid":"3486832","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Black","score":"230.12%"},{"specid":"3486118","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Purple","score":"230.12%"},{"specid":"6575615","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. SP-5x7","score":"230.12%"},{"specid":"3182606","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Rainbow Foil","score":"206.51%"},{"specid":"3290898","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Memorial Day Camo","score":"206.51%"},{"specid":"3382730","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Gold Foil","score":"206.51%"},{"specid":"3480943","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Mother\u0027s Day Pink","score":"206.51%"},{"specid":"3481849","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Father\u0027s Day Blue","score":"206.51%"},{"specid":"3483733","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Independence Day","score":"206.51%"},{"specid":"3633310","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Vintage Stock","score":"206.51%"},{"specid":"3649859","sport":"Baseball Cards","description":"2020 Topps 168 Fernando Tatis Jr. Advanced Stat","score":"206.51%"},{"specid":"3765561","sport":"Baseball Cards","description":"2020 Topps Chrome Sapphire Edition 168 Fernando Tatis Jr.","score":"206.51%"},{"specid":"3786644","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Retail Foilboard","score":"206.51%"},{"specid":"3787457","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Hobby Foilboard","score":"206.51%"},{"specid":"3789403","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Gold Stars","score":"206.51%"},{"specid":"3790179","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Blue","score":"206.51%"},{"specid":"3790919","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Orange","score":"206.51%"},{"specid":"3792370","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. Foilfractor 1/1","score":"206.51%"},{"specid":"3791656","sport":"Baseball Cards","description":"2020 Topps Complete Set 168 Fernando Tatis Jr. 1st Edition","score":"206.51%"}]);'

data = re.search(r"\((.*)\);", s).group(1)
data = json.loads(data)

# pretty print the data:
print(json.dumps(data, indent=4))

打印:

[
    {
        "specid": "2972178",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr.",
        "score": "230.12%"
    },
    {
        "specid": "2972179",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. SP",
        "score": "230.12%"
    },
    {
        "specid": "2972180",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Ssp",
        "score": "230.12%"
    },
    {
        "specid": "3122355",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Yellow",
        "score": "230.12%"
    },
    {
        "specid": "3202267",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Gold",
        "score": "230.12%"
    },
    {
        "specid": "3382322",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Clear",
        "score": "230.12%"
    },
    {
        "specid": "3486832",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Black",
        "score": "230.12%"
    },
    {
        "specid": "3486118",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Purple",
        "score": "230.12%"
    },
    {
        "specid": "6575615",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. SP-5x7",
        "score": "230.12%"
    },
    {
        "specid": "3182606",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Rainbow Foil",
        "score": "206.51%"
    },
    {
        "specid": "3290898",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Memorial Day Camo",
        "score": "206.51%"
    },
    {
        "specid": "3382730",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Gold Foil",
        "score": "206.51%"
    },
    {
        "specid": "3480943",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Mother's Day Pink",
        "score": "206.51%"
    },
    {
        "specid": "3481849",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Father's Day Blue",
        "score": "206.51%"
    },
    {
        "specid": "3483733",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Independence Day",
        "score": "206.51%"
    },
    {
        "specid": "3633310",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Vintage Stock",
        "score": "206.51%"
    },
    {
        "specid": "3649859",
        "sport": "Baseball Cards",
        "description": "2020 Topps 168 Fernando Tatis Jr. Advanced Stat",
        "score": "206.51%"
    },
    {
        "specid": "3765561",
        "sport": "Baseball Cards",
        "description": "2020 Topps Chrome Sapphire Edition 168 Fernando Tatis Jr.",
        "score": "206.51%"
    },
    {
        "specid": "3786644",
        "sport": "Baseball Cards",
        "description": "2020 Topps Complete Set 168 Fernando Tatis Jr. Retail Foilboard",
        "score": "206.51%"
    },
    {
        "specid": "3787457",
        "sport": "Baseball Cards",
        "description": "2020 Topps Complete Set 168 Fernando Tatis Jr. Hobby Foilboard",
        "score": "206.51%"
    },
    {
        "specid": "3789403",
        "sport": "Baseball Cards",
        "description": "2020 Topps Complete Set 168 Fernando Tatis Jr. Gold Stars",
        "score": "206.51%"
    },
    {
        "specid": "3790179",
        "sport": "Baseball Cards",
        "description": "2020 Topps Complete Set 168 Fernando Tatis Jr. Blue",
        "score": "206.51%"
    },
    {
        "specid": "3790919",
        "sport": "Baseball Cards",
        "description": "2020 Topps Complete Set 168 Fernando Tatis Jr. Orange",
        "score": "206.51%"
    },
    {
        "specid": "3792370",
        "sport": "Baseball Cards",
        "description": "2020 Topps Complete Set 168 Fernando Tatis Jr. Foilfractor 1/1",
        "score": "206.51%"
    },
    {
        "specid": "3791656",
        "sport": "Baseball Cards",
        "description": "2020 Topps Complete Set 168 Fernando Tatis Jr. 1st Edition",
        "score": "206.51%"
    }
]