![](/img/trans.png)
[英]Getting the track's ID from a playlist with Spotify's API in Python
[英]Getting API's using Python
我一直在尝试从BTC-E价格API获取价格,例如,我不能仅指定price[109:116]
。 因为如果发生这种情况,它只会以错误的格式打印2个数字。 我只需要掌握“ last:”之后的内容即可。
from urllib2 import Request, urlopen, URLError
def btceapi():
request = Request('https://btc-e.com/api/2/btc_usd/ticker')
try:
response = urlopen(request)
price = response.read()
print price[109:116]
except URLError, e:
print 'Not Found'
btceapi()
您从API检索的price
变量是
{“ ticker”:{“ high”:298.99899,“ low”:263.20001,“ avg”:281.0995,“ vol”:10566249.17861,“ vol_cur”:37737.87504,“ last”:291,“ buy”:291.493,“卖出“:291.001,”更新“:1436554875,” server_time“:1436554876}}'
那是JSON ,您可以使用以下命令将其解析为字典:
import json
<snip...>
price = response.read()
print json.loads(price)["ticker"]["last"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.