This is my code:
JavaScript
x
7
1
import requests
2
import json
3
import re
4
requisicao = requests.get('https://api.binance.com/api/v3/ticker/price?symbol=ETHUSDT')
5
cotacao = json.loads(requisicao.text)
6
print ('BINANCE BTC = U$',cotacao)
7
OUTPUT
JavaScript
1
2
1
{'symbol': 'ETHUSDT', 'price': '2013.44000000'}
2
and that is not what I wanted,
This is what I wanted it to look like: 2013.44000000
, only the digits
Advertisement
Answer
You need to define which object you want from the response, for this case we have two options:
JavaScript
1
2
1
cotacao['symbol']
2
or
JavaScript
1
2
1
cotacao['price']
2
So, for your need we can define it like this:
JavaScript
1
8
1
import requests
2
import json
3
import re
4
5
requisicao = requests.get('https://api.binance.com/api/v3/ticker/price?symbol=ETHUSDT')
6
cotacao = json.loads(requisicao.text)
7
print (cotacao['price'])
8
Output:
JavaScript
1
2
1
2013.44000000
2