【发布时间】:2015-11-09 12:35:03
【问题描述】:
我正在尝试下载 2015 年加拿大联邦选举的所有候选人的数据。有一个名为 opennorth 的服务有一个 API,允许您通过向该 url 发送请求来执行此操作:
https://represent.opennorth.ca/candidates/?limit=1000
1000 个候选人是您在单个请求中被允许的限制,但肯定还有更多。我想知道如何获得下一页结果。来自他们自己的文档:
要下载所有代表,请发送请求至 https://represent.opennorth.ca/representatives/?limit=1000 并关注 元字段下的下一个链接,直到您到达末尾。我们主办 GitHub 上的 shapefile 和邮政编码索引。
这是“代表”数据,但我认为“候选人”也是如此。我不明白他们所说的“跟随元字段下的下一个链接直到你到达终点”是什么意思。有人能告诉我这个吗?
到目前为止,这是我的脚本:
import urllib
with urllib.request.urlopen(r"https://represent.opennorth.ca/candidates/house-of-commons/?limit=1000") as url:
with open(r"F:\electoral_map\candidates_python\candidates.js", "wb+") as f:
f.write(url.read())
print("all done")
【问题讨论】:
标签: python web-scraping urllib