我需要从此API https://api.storj.io/contacts/f52624d8ef76df81c40853c22f93735581071434(示例节点)
获取数据这是我的代码(python):
import requests f = requests.get('https://api.storj.io/contacts/f52624d8ef76df81c40853c22f93735581071434') print f.text
我想在txt文件的三个后续行中仅保存protocol,responseTime和信誉。它应该看起来像这样::
protocol: 1.2.0 responseTime: 8157.912472694088 reputation: 1377
不幸的是,我在这一点上陷入困境,我无法以任何方式处理这些数据
答案 0 :(得分:2)
function onFilterTextBoxChanged() {
gridOptions.api.setQuickFilter(document.getElementById('filter-text-box').value);
}
希望它有所帮助!干杯
答案 1 :(得分:1)
这是一种非常未经精炼的方式来做你想要的东西,你可以建立起来。你需要在text.txt的路径/文件名中加上。
import requests
import json
f = requests.get('https://api.storj.io/contacts/f52624d8ef76df81c40853c22f93735581071434')
t = json.loads(f.text)
with open('text.txt', 'a') as mfile:
mfile.write("protocol: {0}".format(str(t['protocol'])))
mfile.write("responseTime: {0}".format(str(t['responseTime'])))
mfile.write("reputation: {0}".format(str(t['reputation'])))
答案 2 :(得分:1)
您只需要转换为JSON对象即可访问密钥
import requests
import simplejson as json
f = requests.get('https://api.storj.io/contacts/f52624d8ef76df81c40853c22f93735581071434')
x = json.loads(f.text)
print 'protocol: {}'.format(x.get('protocol'))
print 'responseTime: {}'.format(x.get('responseTime'))
print 'reputation: {}'.format(x.get('reputation'))