Python 的 API 请求的查询字符串

时间:2021-06-04 14:40:46

标签: python api python-requests

我正在尝试为我的请求检索接下来的 10 个结果,但我不确定如何去做。我的前 10 个结果包括一个“nextProjectId”,它是查询接下来的 10 个结果所需的 Id。但我不确定如何将它添加到我的下一个请求的 url 字符串中。

host = "https://api.globalgiving.org"
operation = "/api/public/projectservice/themes/env/projects"
api_key = '******'
url = host + operation + "?" +"api_key=" + api_key
response = requests.get(url, verify=False)
data_dict = xmltodict.parse(response.text)

根据 API 文档,一个请求最多只能拉取 10 个结果: 来源: 此操作检索特定主题中所有项目的信息。但是,结果集限制为每个请求最多 10 个结果。如果有更多可用结果,响应将返回两个额外的元素 hasNext 和 nextProjectId。请注意,如果没有更多可用结果,则这两个元素不存在。 hasNext 元素指示是否有更多可用结果,nextProjectId 元素指示要包含在查询字符串中以检索下一组结果的下一个项目 ID。这是一个非安全请求,如 URL 路径中的“/public/”元素所示,因此不需要访问令牌(身份验证)。

示例结果:

OrderedDict([('projects',
              OrderedDict([('@numberFound', '32'),
                           ('hasNext', 'true'),
                           ('nextProjectId', '49406'),
                           ('project',
                            [OrderedDict([('active', 'true'),
                                          ('activities',
                                           'Replanting damaged forests restores lost habitat, and engages local people in protecting the park in the future. We set up organic tree nurseries and forestry centres near degraded forest areas, and provide reforestation training for communities. This project focuses on rehabilitating degraded land within the Gunung Leuser National Park, planting hundreds of thousands of tree seedlings.'),

0 个答案:

没有答案
相关问题