zoukankan      html  css  js  c++  java
  • Python 下载图片的三种方法

    https://blog.csdn.net/qq_34504481/article/details/79716106

    ********************************************************************

    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')
  • 相关阅读:
    670. Maximum Swap
    126. Word Ladder II
    695. Max Area of Island
    689. Maximum Sum of 3 Non-Overlapping Subarrays
    667. Beautiful Arrangement II
    前端开发-css
    前端开发-html
    mysql补充
    pythonl操作数据库
    mysql索引原理
  • 原文地址:https://www.cnblogs.com/zhao1949/p/11375755.html
Copyright © 2011-2022 走看看