228.爬取图片
import urllib.request
import gevent
from geventimport monkey
monkey.patch_all()
def downloader(img_name, img_url):
# https://rpic.douyucdn.cn/live-cover/appCovers/2019/11/13/7596767_20191113180919_small.jpg
# https://rpic.douyucdn.cn/live-cover/appCovers/2018/04/12/3866447_20180412205544_small.jpg
req = urllib.request.urlopen(img_url)
img_content = req.read()
with open('2.jpg','wb')as f:
f.write(img_content)
def main():
gevent.joinall([
gevent.spawn(downloader,"1.jpg", "https://rpic.douyucdn.cn/live-cover/appCovers/2019/11/13/7596767_20191113180919_small.jpg"),
gevent.spawn(downloader,"2.jpg","https://rpic.douyucdn.cn/live-cover/appCovers/2018/04/12/3866447_20180412205544_small.jpg")
])
if __name__ =="__main__":
main()