将 requests.get 与 python 合并
Merge requests.get with python
有这两个请求,我如何将结果合并到一个变量中?
listone=requests.get(URL + API_URL + endpoint,
headers=API_HEADER,
params=getparams)
#some missing code that do stuff
listtwo=requests.get(URL + API_URL + endpoint,
headers=API_HEADER,
params=getparams)
谢谢
url_header_list = [
(url1, headers1),
(url2, headers2),
]
items = []
# You can change your headers and url in any way you want, not just like that
for url, headers in url_header_list:
# And this you need to do for each pair of url and headers
response = requests.get(url, headers=headers).json()
items.extend(response['items'])
items 将包含每个响应中的所有项目。
有这两个请求,我如何将结果合并到一个变量中?
listone=requests.get(URL + API_URL + endpoint,
headers=API_HEADER,
params=getparams)
#some missing code that do stuff
listtwo=requests.get(URL + API_URL + endpoint,
headers=API_HEADER,
params=getparams)
谢谢
url_header_list = [
(url1, headers1),
(url2, headers2),
]
items = []
# You can change your headers and url in any way you want, not just like that
for url, headers in url_header_list:
# And this you need to do for each pair of url and headers
response = requests.get(url, headers=headers).json()
items.extend(response['items'])
items 将包含每个响应中的所有项目。