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')
  • 相关阅读:
    php数组
    php运算符
    PHP数据类型
    面向对象3和继承
    面向对象2
    面向对象1
    语法整理php
    语法整理
    ajax
    数据库4
  • 原文地址:https://www.cnblogs.com/Garvey/p/6700070.html
Copyright © 2011-2022 走看看