小编Nik*_*Nik的帖子

偏移量为 100 的分页循环

我正在编写一个代码,从 API 获取记录,并且该 API 实现了分页,最多允许 100 条记录。所以我必须循环100的倍数。目前我的代码比较总记录并从偏移量100 开始循环,然后是 101,102,103 等。我希望它以 100 为单位循环(如 100,200,300),并在偏移量大于总记录时立即停止。我不知道如何做到这一点,我有部分代码增加 1 而不是 100,并且在需要时不会停止。有人可以帮我解决这个问题吗?

import pandas as pd
from pandas.io.json import json_normalize

#Token for Authorization
API_ACCESS_KEY = 'Token'
Accept='application/xml'

#Query Details that is passed in the URL
since = '2018-01-01'
until = '2018-02-01'
limit = '100'
offset = '0'
total = 'true'

def get():

    url_address = "https://mywebsite/web?offset="+str('0') 
    headers = {
        'Authorization': 'token={0}'.format(API_ACCESS_KEY),
        'Accept': Accept,
    }
    querystring = {"since":since,"until":until, "limit":limit, "total":total}


    # find out total number of …
Run Code Online (Sandbox Code Playgroud)

python api pagination

2
推荐指数
1
解决办法
9679
查看次数

标签 统计

api ×1

pagination ×1

python ×1