我有两对网址,我使用的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响应中。