如何使用python 批量下载图片
发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,本篇内容主要讲解"如何使用python 批量下载图片",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"如何使用python 批量下载图片"吧!from tim
千家信息网最后更新 2025年02月07日如何使用python 批量下载图片
本篇内容主要讲解"如何使用python 批量下载图片",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"如何使用python 批量下载图片"吧!
from time import timefrom threading import Threadimport requestsclass DownloadHanlder(Thread): def __init__(self, url): super().__init__() self.url = url def run(self): filename = self.url[self.url.rfind('/') + 1:] #get the filename from origin url with the value of : # 'https://cache.yisu.com/upload/information/20210521/347/345442.jpg' resp = requests.get(self.url) with open('./pictest/' + filename, 'wb') as f: f.write(resp.content)def main(): # 通过requests模块的get函数获取网络资源 resp = requests.get( 'http://api.tianapi.com/meinv/?key=keyvalue4&num=10') # 将服务器返回的JSON格式的数据解析为字典 data_model = resp.json() for mm_dict in data_model['newslist']: url = mm_dict['picUrl'] # 通过多线程的方式实现图片下载 DownloadHanlder(url).start()if __name__ == '__main__': main()
线程模块提供了Thread类来处理线程,Thread类提供了以下方法: run(): 用以表示线程活动的方法。 start():启动线程活动。
其中,Thread类中含有方法start() 其定义如下:
def start(self): """Start the thread's activity. It must be called at most once per thread object. It arranges for the object's run() method to be invoked in a separate thread of control. This method will raise a RuntimeError if called more than once on the same thread object. """ if not self._initialized: raise RuntimeError("thread.__init__() not called") if self._started.is_set(): raise RuntimeError("threads can only be started once") with _active_limbo_lock: _limbo[self] = self try: _start_new_thread(self._bootstrap, ()) except Exception: with _active_limbo_lock: del _limbo[self] raise self._started.wait()
到此,相信大家对"如何使用python 批量下载图片"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
线程
图片
方法
内容
模块
学习
活动
实用
更深
兴趣
函数
图片下载
字典
实用性
实际
操作简单
数据
方式
更多
朋友
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
做兼职什么app软件开发
网络安全侦察局
小学国家网络安全宣传周活动
服务器城市列表广东
国内金融数据库
元神用哪个服务器好
网络技术应用的书
如何从数据库取消文件夹
网络技术的实习科目
共建机制和网络安全等级
vr软件开发专业学什么
服务器显卡驱动怎么修复
sql数据数据库
工业软件开发定制价格
svn的服务器搭建要多久
麒麟系统代理服务器配置
华为服务器主板是什么型号
私有服务器怎么赚钱
万方数据库检索结果处理
成都学习数据库
网络技术视屏
计算机网络技术就业前景调研
地铁软件开发技术管理怎么样
软件开发项目是否需要进项票
数据库的物理删除和
网站和数据库 安全
数据库招标公告
阿里服务器在哪儿
大学生网络安全广告
数据库技术实训报告总结