需要实现的是:
1.执行x请求,获取response
2.提取response中list,把list中需要的值循环写入1.txt文件
实现如下
#tokensso是变量,取值于登录接口的response.data.token
url = "https://xxxx"
request_headers = {
"Authorization": tokensso,
"Content-Type": "application/json"
}
login_data = {
"approvalFlg": "false",
"pageNo": 1,
"pageSize": 300,
"processInstanceNameOrUserName": "",
"sortType": 1
}
res1 = requests.post(url, json=login_data, headers=request_headers).json()
list=res1.get("data").get("list")
#打开data文件夹下1.txt
file_handle = open('data/1.txt', mode='w')
for i in range(len(list)):
reAppPageId=list[i].get("reAppPageId")
reInsRecipientId=list[i].get("reInsRecipientId")
reInstanceId=list[i].get("reInstanceId")
#循环写入1.txt文件
file_handle.write(tokensso+","+reAppPageId+","+reInsRecipientId+","+reInstanceId+"\n")