简体   繁体   English

将 requests.get 与 python 合并

[英]Merge requests.get with python

Having this two request how can i merge the results in one variable?有了这两个请求,我如何将结果合并到一个变量中?

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)

Thanks谢谢

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 will contain all the items from each response. items 将包含每个响应中的所有项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM