• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Python的请求参数/处理API分页

用户头像
it1352
帮助1

问题说明

我与天使列表(AL)API玩耍,并要拉在San旧金山的所有作业。
因为我无法找到该API的积极Python包装(如果我没有取得任何进展,我想我会做我自己),我使用的请求库。

I'm playing around with the Angel List (AL) API and want to pull all jobs in San San Francisco. Since I couldn't find an active Python wrapper for the api (if I make any headway, I think I'd like to make my own), I'm using the requests library.

美联API的结果是分页,我想不出如何超越结果的第一页。

The AL API's results are paginated, and I can't figure out how to move beyond the first page of the results.

下面是我的code:

import requests
r_sanfran = requests.get("https://api.angel.co/1/tags/1664/jobs").json()
r_sanfran.keys()
# returns [u'per_page', u'last_page', u'total', u'jobs', u'page']
r_sanfran['last_page']
#returns 16
r_sanfran['page']
# returns 1

我尝试添加参数 requests.get ,但没有奏效。我也尝试过一些非常愚蠢的 - 改变这样的页键被神奇地将分页对我的价值。

I tried adding arguments to requests.get, but that didn't work. I also tried something really dumb - changing the value of the 'page' key like that was magically going to paginate for me.

如。 r_sanfran ['页'] = 2

我猜测它的东西比较简单,但我似乎无法弄清楚所以任何帮助将是真棒。

I'm guessing it's something relatively simple, but I can't seem to figure it out so any help would be awesome.

感谢一如既往。

天使列表API文档如果它是有帮助的。

正确答案

#1

last_page ,并在范围内的每个页面的GET请求:

Read last_page and make a get request for each page in the range:

import requests

r_sanfran = requests.get("https://api.angel.co/1/tags/1664/jobs").json()
num_pages = r_sanfran['last_page']

for page in range(2, num_pages   1):
    r_sanfran = requests.get("https://api.angel.co/1/tags/1664/jobs", params={'page': page}).json()
    print r_sanfran['page']
    # TODO: extract the data

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfffjg
系列文章
更多 icon
同类精品
更多 icon
继续加载