python实现 协程多任务图片下载器
Python 实现 协程 多任务
2023-09-14 09:07:32 时间
import urllib.request import gevent from gevent import monkey monkey.patch_all() def main(): urlList = ['http://10.194.116.146/CSSImg/hkjc_logo.png', 'http://10.194.109.125/Content/Swagger.png', 'http://10.194.109.125/favicon.ico'] fileNameList = ["4.png", "5.png", "6.png"] ge = gevent.spawn(downloadImages, urlList, fileNameList) ge.join() def downloadImages(urlList, fileNameList): i = 0 for value in urlList: response_data = urllib.request.urlopen(value) with open(fileNameList[i], "wb") as file: while True: file_data = response_data.read(1024) if file_data: file.write(file_data) else: break i += 1 if __name__ == '__main__': main()
相关文章
- 手写代码实现卷积操作(Python)
- 情人节来了,教你个用 Python 表白的技巧「建议收藏」
- Python实现索伯尔算子[通俗易懂]
- Python 2.7.6软件下载和安装教程
- 【说站】python thread模块如何实现多线程
- 【说站】python链表实现左移和右移
- 【说站】python ChainMap如何实现字典操作
- Python爬虫抓取网站模板的完整版实现
- 机器学习——决策树模型:Python实现
- Python保存json_python保存json文件
- python制作自动交易程序_Python如何实现自动化交易
- 数据结构与算法Python_数据结构与算法python语言实现
- python做微信回复机器人_Python自动化脚本
- python分段线性插值_Python实现分段线性插值
- 软件测试|教你使用Python实现五子棋游戏(一)
- Python实现变量分箱及应用
- Python面向对象编程-魔术方法-__str__和__repr__方法
- python-协程并发-多任务协程的实现方式(一)
- Python实现二分查找(二分查询)详解编程语言
- 开发Linux下Python编程:实现自己的开发梦想(linux下python)
- Python实现快速连接Redis数据库(python连接redis)
- 从 Python 连接到 MySQL:实现更多强大的数据库应用(python和mysql)
- python用Redis与Python实现大数据收集与分析(redis 联合)
- python二叉树遍历的实现方法
- python中stdout输出不缓存的设置方法
- python和shell实现的校验IP地址合法性脚本分享
- python实现定制交互式命令行的方法
- python实现的一个火车票转让信息采集器
- python实现进程间通信简单实例
- python处理文本文件实现生成指定格式文件的方法