【问题标题】:Merge requests.get with python将 requests.get 与 python 合并
【发布时间】:2020-12-27 13:26:10
【问题描述】:

有这两个请求,我如何将结果合并到一个变量中?

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)

谢谢

【问题讨论】:

    标签: python merge get request


    【解决方案1】:
    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 将包含来自每个响应的所有项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 1970-01-01
      • 2015-03-24
      相关资源
      最近更新 更多