requests库 如何循环获取分页接口的全部数据
由于框架限制page最大上限为1000,默认10条
部分代码
author = 'Leo'
import requests
import json
import time
url = "http://order-full-process/list?page=0&size=10"
headers = heade_D()
ir = ApiRequest()
data = {
'''''''
}
result = ir.run_method(url=url, method='post', data=data, headers=headers)
json_data = json.loads(result) # 转换
orderno_list = [i['orderNo'] for i in json_data.get('content', [])]
Status = [i['orderStatus'] for i in json_data.get('content', [])]
sums = len(orderno_list)
print(f'订单数量:{sums}')
//试了循环调用
def url_info():
url_list = ['http://order-detail?page={}&size=10&orderNo='.format(i) for i in range(20)]
return url_list
这样返回的数据会有重复值,不知道啥原因,
返回test数据:
content: [{id: "501712619678683136", dispatchCode: "MD00000271", dispatchName: "106",…},…]
empty: false
number: 0
numberOfElements: 10
size: 10
totalElements: 31
totalPages: 4
又不是死的数据,比如有人增加了删除了,肯定会变。
数据本身就是实时的,实时拿到数据判定是否有重复值就行了,和实时统计,值做简单的数据分析
数据两个小时更新一次,两个小时内不会有任何变化的.