Python的请求参数/处理API分页
问题说明
我与天使列表(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文档如果它是有帮助的。
正确答案
读 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
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22