2019-07-02作业

import urllib.request

import gevent

from gevent import monkey

monkey.patch_all()

def downloader(name,url):

req = urllib.request.urlopen(url)

img_content = req.read()

with open(name,"wb") as f:

f.write(img_content)

def main():

gevent.joinall([

        gevent.spawn(downloader,"1.jpg","https://rpic.douyucdn.cn/asrpic/190703/748396_1355.png"),

        gevent.spawn(downloader,"2.jpg","https://sta-op.douyucdn.cn/dy-listicon/5b1f9d1c6f8078af84a700abd54e0fad.png"),

])

if __name__ == "__main__":

main()

你可能感兴趣的:(2019-07-02作业)