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

Time:06-05

I am using a get request to get this response:

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%"}]);

I see in the curly brackets look like python dictionarys with key:value pairs but I have never seen a response with multiple dictionarys like this. I have tried treat it like json data since that's what google chrome dev tools said the response was "application/json; charset=utf-8".

What I am looking for is to take the first five curly brakets and put them into 1 dictionary but I don't even know how to define one as its own yet. Any help would be appreciated.

CodePudding user response:

To parse the data into a Python dictionary you can use re/json modules:

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))

Prints:

[
    {
        "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%"
    }
]
  • Related