That data is in JSON format, which is roughly equivalent to a dictionary in Python. I'm not an expert in Python, but I believe that you'll need to import the json
module and parse the data with .loads()
- then you can access the values as properties of the dictionary.
So for example, your data looks like this:
{"BTC":0.1434,"USD":387.92,"EUR":343.51}
In your script, you'll import json
, put the data into a variable, and parse it as a dictionary:
import json
json_string = '{"BTC":0.1434,"USD":387.92,"EUR":343.51}'
parsed_json = json.loads(json_string)
Now if you reference parsed_json
, you can access the values:
print parsed_json['BTC']
# 0.1434
print parsed_json['EUR']
# 343.51
And so on.
Edit
After re-reading your question, I feel like what you are aiming for is some combination of the accepted answer and mine. Here's what I think you're looking for (borrowing from the accepted answer):
>>> import requests
>>> data = requests.get("https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=BTC,USD,EUR"
).json()
>>> data['USD']
387.92
>>> data['BTC']
0.1434
The data returned by requests.get()
is already parsed, so there's no need to parse it again with json.loads()
. To access the value of a dictionary's attribute, type the name of the dictionary and then the attribute in brackets.