Python查询限制为300个来自API的结果,如何添加分页更新pandas选项卡

2024-09-29 19:28:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用MailgunAPI来获取与某个事件一起发送的电子邮件数量的一些数据,然后是邮件的主题和收件人等详细信息

答复限制在300人,但我需要几千人

我知道我需要使用分页,但我不知道如何使用它。我想应该是这样的:

nextUrl = status['paging']['next']
    data = requests.get(nextUrl, auth=("api", API_KEY), params ={"limit":300})

这是我目前为止的代码:

^{pr2}$

在中创建此表:

enter image description here

现在这个表正是我想要的,但是我不想被限制在300个结果之内。我可能需要成千上万的人

有人能告诉我如何使用分页来做到这一点吗?在

非常感谢


Tags: 数据主题data数量电子邮件status事件邮件
1条回答
网友
1楼 · 发布于 2024-09-29 19:28:10

documentation声明始终返回“上一个url”和“下一个url”。在

...Both next and previous page URLs are always returned, even when retrieving one of them makes no sense. There are two such cases: previous page URL for the first result page, and next page URL for the last result page; requesting these URLs always returns an empty result page. ...

所以,看来你得反复打电话(如这样)。注意:这是伪代码,只是一个想法:

url = "https://api.mailgun.net/v3/#"
last_next_url = None
while url is not last_next_url:
    delivered = requests.get(url,
    auth=("api", "key-#"),
    params={"event" : "delivered",
            "limit" : 300}) 
    ...
    # TODO: i'm not sure about HTTP response code here:
    if delivered.status >= 200 and delivered.status < 300: 
        url = raw['next_page_url']

相关问题 更多 >

    热门问题