Python 下载图片的三种方法
2024-10-18 23:55:40
import os
os.makedirs('./image/', exist_ok=True)
IMAGE_URL = "http://image.nationalgeographic.com.cn/2017/1122/20171122113404332.jpg"
def urllib_download():
from urllib.request import urlretrieve
urlretrieve(IMAGE_URL, './image/img1.png')
def request_download():
import requests
r = requests.get(IMAGE_URL)
with open('./image/img2.png', 'wb') as f:
f.write(r.content)
def chunk_download():
import requests
r = requests.get(IMAGE_URL, stream=True)
with open('./image/img3.png', 'wb') as f:
for chunk in r.iter_content(chunk_size=32):
f.write(chunk)
urllib_download()
print('download img1')
request_download()
print('download img2')
chunk_download()
print('download img3')
最新文章
- [Java] Spring MVC 知识点
- SQLite学习笔记(七)&;&;事务处理
- 当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'OrderList' 中的标识列插入显式值
- java服务器端编程
- (二)cordova+framework7入门——笑笑APP
- BackTrack5-r3硬盘安装
- Effective Java 阅读笔记——枚举和注解
- EasyUI tab常用
- mvc4帮助类
- vmware 几种联网的方式,怎样实现虚拟机上网
- struts2 convention-plugin
- Physiological Processes of Speech Production--Reading Notes (8)
- openlayers应用(二):加载百度离线瓦片
- PHP 命名空间与自动加载机制
- 在windows 下使用eclipse进行编译和烧写
- sqlserver2008 链接服务器 2000
- JDK8中JVM堆内存划分
- C++ string中的几个小陷阱,你掉进过吗?
- 大数据系列之数据仓库Hive原理
- WCF系列教程之WCF客户端调用服务