下载图片


下载图片的三种方式

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):

文章作者: 小游
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 小游 !
  目录