我成功地从JSON中提取响应。但是,我无法列出所有内容或提取我需要的密钥及其对
以下是我的代码:
import requests
response = requests.get("https://www.woolworths.com.au/apis/ui/Product/Specials/half-price?GroupID=948&isMobile=false&pageNumber=1&pageSize=36&richRelevanceId=SP_948&sortType=Personalised")
data = response.json()
我尝试data['Stockcode']
但没有运气或我使用data['Product']
它说:
>>> data['Product']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'Product'
>>> data['Products']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'Products'
答案 0 :(得分:0)
尝试:
>>> data['Items'][0]['Products']
打印数据并查看其数据结构如何构建它然后您可以根据需要提取值