前提:
提前安装的requests用来模拟发送请求,gevent用来实现协程
import requests import gevent class Simulate(): count = 0 def __init__(self): Simulate.count += 1 def mock(self): url = "https://www.baidu.com/img/bd_logo1.png?where=super" response = requests.get(url=url) with open('./baidu.png', 'wb') as f: f.write(response.content) if __name__ == '__main__': for i in range(10): s =Simulate().mock g = gevent.spawn(s)