简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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