我一直在尝试从BTC-E price API获取一个价格,我不能仅仅指定price[109:116]
作为例子。因为如果发生这种情况,它只会以错误的格式打印2个数字。我只需要抓住“最后一次”之后的内容
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
变量是这就是JSON,你可以用它解析成字典:
相关问题 更多 >
编程相关推荐