- import os
- os.makedirs('./image/', exist_ok=True)
- IMAGE_URL = "http://www.image.com/3.jpg"
- def urllib_download():
- from urllib.request import urlretrieve
- urlretrieve(IMAGE_URL, './image/3.jpg')
- 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')
Python 下载图片的三种方法【总结】
猜你喜欢
转载自blog.csdn.net/wangpengfei163/article/details/80235096
今日推荐
周排行