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

    一. urllib

    # python2
    import urllib url
    = r"https://storage.googleapis.com/imgfave/image_cache/1491751695365459.jpg" path = r"D:my.jpg"   #字符串前加r 防止被转义 data = urllib.urlretrieve(url,path) #py -3 #data = urllib.request.urlretrive(url,path)
    #python3
    import urllib.request 
    url = r"https://storage.googleapis.com/imgfave/image_cache/1491751695365459.jpg"  
    path = r"D:my.jpg"    #字符串前加r 防止被转义
    data = urllib.request.urlretrieve(url,path)

    二. requests

    import requests
    url = 'https://storage.googleapis.com/imgfave/image_cache/1491751695365459.jpg'
    with open(r'D:sss.jpg', 'wb') as handle:
        response = requests.get(url, stream=True)
        for block in response.iter_content(1024):
            if not block:
                break
            handle.write(block)
        print('done')
  • 相关阅读:
    javascript基础
    html基础
    css基础
    django-session和cookie
    rest架构
    django-models
    django-templates
    Alignment
    ural 1225.Flags
    ural 1009. K-based Numbers
  • 原文地址:https://www.cnblogs.com/Garvey/p/6700070.html
Copyright © 2011-2022 走看看