【发布时间】:2019-11-26 18:24:20
【问题描述】:
您好,我仍处于学习 Python 的初级阶段。我正在尝试使用他们的 api 系统从 Coinmarketcap.com 提取数据。我可以使用一本大字典获得输出,但似乎无法弄清楚如何提取特定数据。我想只收到'价格':和'最后更新'。
我尝试引用 .loads 并将数据切片到列表中。我也尝试在字典中建立索引,但输出中的嵌套字典让我难以理解。我看过很多 youtube 教程并在 Google 上寻求帮助,但无法找到解决方案。任何帮助将不胜感激!
import requests
import json
url ='https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
headers = {'Accepts': 'application/json', 'X-CMC_PRO_API_KEY': api_key}
parameters = {'symbol': 'ADA'}
response = requests.get(url, headers = headers, params = parameters)
data = response.json()
data_str = json.dumps(data, indent = 2)
print(data_str)
这是字典的输出:
{"status": {"timestamp": "2019-07-17T20:54:40.829Z", "error_code": 0, "error_message": null, "elapsed": 7, "credit_count": 1} ,“数据”:{“ADA”:{“id”:2010,“名称”:“卡尔达诺”,“符号”:“ADA”,“slug”:“卡尔达诺”,“num_market_pairs”:90,“添加日期” : "2017-10-01T00:00:00.000Z", "tags": ["mineable"], "max_supply": 45000000000, "circulating_supply": 25927070538, "total_supply": 31112483745, "platform": null, "cmc_rank ": 12, "last_updated": "2019-07-17T20:54:04.000Z", "quote": {"USD": {"price": 0.056165857414, "volume_24h": 102375843.427606, "percent_change_1h": -0.816068, “percent_change_24h”:5.42849,“percent_change_7d”:-21.8139,“market_cap”:1456216147.0000284,“last_updated”:“2019-07-17T20:54:04.000Z”}}}}}
【问题讨论】:
标签: python json dictionary