使用PYTHON和JSON传递API页面
这是我的API完整输出-JSON文件使用PYTHON和JSON传递API页面,python,json,api,Python,Json,Api,这是我的API完整输出-JSON文件 "took": 150, "total": 3377, "hits": [{ Extra - not relevant JSON information }, { Extra - not relevant JSON information }, ....... 总数-平均职位总数 API限制为每次请求250个帖子
"took": 150,
"total": 3377,
"hits": [{
Extra - not relevant JSON information
},
{
Extra - not relevant JSON information
},
.......
总数-平均职位总数
API限制为每次请求250个帖子
我需要遍历页面并获取所有帖子,然后写入单个JSON文件
我所拥有的:
这是我从API中提取数据的方式:
def post_拉具():
这是我的python代码,它获取数据,修改数据并写入文件:
def modify_file_emoji(FILE_NAME,OUTPUT):
print("Ready to remove issues from {} file".format(OUTPUT))
jsonFile = open(FILE_NAME, "r")
data = json.load(jsonFile)
jsonFile.close()
#Modify JSON File, that BQ will accept it.
with open(OUTPUT, "w+") as outfileJSON:
outfileJSON.write(json.dumps(data['hits']))
with open(OUTPUT, "r") as infileInsight:
insightData = infileInsight.read()\
.replace("","")\
with open(OUTPUT, "w+") as outfileInsight:
outfileInsight.write(insightData)
print("File: {} modified - removed all the known issues".format(OUTPUT))
你的问题到底是什么?这只是当前语句的集合。你有错误吗?@roganjosh如果我有3377篇帖子,我不知道通过API页面的方式是什么,但我只能查看每个请求250篇(限制),获得帖子251-500、501-750等等的方式是什么?@roganjosh我知道可以使用-json.dumps(data['total')作为总帖子来获取变量,但不确定如何创建一个将通过API页面的循环。
def modify_file_emoji(FILE_NAME,OUTPUT):
print("Ready to remove issues from {} file".format(OUTPUT))
jsonFile = open(FILE_NAME, "r")
data = json.load(jsonFile)
jsonFile.close()
#Modify JSON File, that BQ will accept it.
with open(OUTPUT, "w+") as outfileJSON:
outfileJSON.write(json.dumps(data['hits']))
with open(OUTPUT, "r") as infileInsight:
insightData = infileInsight.read()\
.replace("","")\
with open(OUTPUT, "w+") as outfileInsight:
outfileInsight.write(insightData)
print("File: {} modified - removed all the known issues".format(OUTPUT))