作业

import urllib.request

import gevent

from gevent import monkey

monkey.patch_all()

def downloader(img_name,img_url):

req = urllib.request.urlopen(img_url)

img_content = req.read()

with open(img_name,'wb') as f:

f.write(img_content)

def main():

gevent.joinall([

gevent.spawn(downloader,'3.jpg','https://huyaimg.msstatic.com/avatar/1008/b7/36b005e3ab0cac6636b54a550bb601_180_135.jpg'),

gevent.spawn(downloader,'4.jpg','https://apic.douyucdn.cn/upload/avatar/face/201609/08/f6c0c08a3f3cb1fd074fe38907ae2508_middle.jpg')

])

if __name__ == '__main__':

main()

你可能感兴趣的:(作业)