【发布时间】:2016-07-31 03:19:56
【问题描述】:
我想知道如何使用两个查询参数向特定 url 发出 GET 请求?这些查询参数包含两个 id 号 到目前为止,我有:
import json, requests
url = 'http://'
requests.post(url)
但他们给了我查询参数 first_id=### 和 last_id=###。我不知道如何包含这些参数?
【问题讨论】:
我想知道如何使用两个查询参数向特定 url 发出 GET 请求?这些查询参数包含两个 id 号 到目前为止,我有:
import json, requests
url = 'http://'
requests.post(url)
但他们给了我查询参数 first_id=### 和 last_id=###。我不知道如何包含这些参数?
【问题讨论】:
要发出 GET 请求,您需要 get() method,参数使用 params 参数:
response = requests.get(url, params={'first_id': 1, 'last_id': 2})
如果响应是 JSON 内容类型,您可以使用 json() 快捷方式将其加载到 Python 对象中:
data = response.json()
print(data)
【讨论】: