使用grequest时加入特定的json响应

时间:2019-04-15 05:09:25

标签: python gevent grequests

我有两对网址,我使用的api每个请求最多只能返回100行。为了并行化我使用grequess模块​​的请求,我如何将每个4个请求返回的json响应加入2个。

def send_requests():
     global stored_responses 
     stored_responses = [] # stored response objects

     event_list = [google.com/api/rows=0-100/,  google.com/api/rows=0-200/, yahoo.com/api/rows=0-100, yahoo.com/api/rows/rows=0-200]

     rs = (grequests.get(u.split(',')[0], headers=headers) for u in event_list) # asynchronus requests
     responses = grequests.imap(rs) # responses as list

     for response in responses:
        if response.status_code != 200:
            continue
        else:
             stored_responses.append(response.json())

我如何将两个google.com请求都加入一个json响应中,并将两个yahoos都加入一个json响应中。

0 个答案:

没有答案