1 回答
TA贡献1786条经验 获得超13个赞
“index”键嵌套在 JSON 消息中的一个数组中(“sections”的值是一个数组)。
这个问题的解决方案可能是:
navi_info = requests.get('https://shopee.co.id/api/v4/recommend/recommend?bundle=top_sold_product_microsite&limit=20&offset=0')
print(navi_info.json()['data']['sections'])
# extracts all the "index" data from all "sections"
index_arrays = [object_['index'] for object_ in navi_info.json()['data']['sections']]
index_array = index_arrays[0] # only one section with "index" key is present
# extract all catIDs from the "index" payload
catIDs = [object_['key'] for object_ in index_array]
payload = {'catID': catIDs}
print(payload)
有效载荷应该看起来像{'catID': ['ID_V2L0_65', 'ID_V2L0_3693', 'ID_V2L0_2', 'ID_V2L0_19', 'ID_V2L0_75', 'ID_V2L0_4040',...]}
添加回答
举报