【发布时间】:2021-06-28 04:02:29
【问题描述】:
对于我的项目,我需要请求一个 api 并将结果存储在一个列表中。但是没有。我需要提供超过 5000 个不同正文值的请求。因此,需要花费大量时间才能完成。有什么方法可以并行发送请求以快速完成该过程。我尝试了一些线程代码,但我无法找出解决这个问题的方法。
import requests
res_list=[]
l=[19821, 29674 , 41983, 40234 ,.....] # Nearly 5000 items for now and the count may increase in future
for i in l:
URL ="https://api.something.com/?key=xxx-xxx-xxx&job_id={0}".format(i)
res = requests.get(url=URL)
res_list.append(res.text)
【问题讨论】:
-
你的问题是?到目前为止,它只是一个声明:“我无法编程我需要的东西”。
标签: python multithreading api python-multiprocessing python-multithreading