import os



import urllib.request



image_url = 'http://img.jingtuitui.com/759fa20190115144450401.jpg'



file_path = 'C:/python-pro/mall_splier'



# file_name =
image_url



try:

    if not os.path.exists(file_path):

        os.makedirs(file_path) #如果没有这个path则直接创建

    file_suffix =
os.path.splitext(image_url)[1]

    print(file_suffix)

    filename = '{}{}'.format(file_path, file_suffix) 拼接文件名。

    print(filename)

    urllib.request.urlretrieve(image_url, filename=filename),利用urllib.request.urltrieve方法下载图片

    print(11111)



except IOError as e:

    print(1, e)



except Exception as e:

    print(2, e)

python实现通过URL下载图片到本地服务器的更多相关文章

  1. QT通过url下载图片到本地

    /* strUrl:下载图片时需要的url strFilePath:下载图片的位置(/home/XXX/YYY.png) */ void ThorPromote::downloadFileFromUr ...

  2. 根据URL下载图片到本地

    /// <summary> /// 下载图片 /// </summary> /// <param name="picUrl">图片Http地址& ...

  3. 利用Python实现从百度下载图片到本地磁盘

    import urllib.request import os import re url=r'http://image.baidu.com/search/index?tn=baiduimage&am ...

  4. 从url下载图片--java与python实现方式比较

    从url下载图片--java与python实现方式比较 博客分类: 技术笔记小点滴 javapython图片下载  一.java的实现方式 首先读取图片 //方式一:直接根据url读取图片 priva ...

  5. JAVA 通过url下载图片保存到本地

    //java 通过url下载图片保存到本地 public static void download(String urlString, int i) throws Exception { // 构造U ...

  6. java根据图片的url地址下载图片到本地

    package com.daojia.haobo.aicircle.util; import sun.misc.BASE64Encoder; import java.io.*; import java ...

  7. php下载图片到本地

    写了一天,就写了这么点代码,凑合用吧. #saveImage.php<?php /** * 图片下载方法,提供两种图片保存方式: * 1.按照图片自带的名称保存 * 2.按照自定义文件名保存 * ...

  8. 通过HttpURLConnection下载图片到本地--下载附件

    一.背景说明 现在我做的系统中,需要有一个下载附件的功能,其实就是下载图片到本地中.相应的图片保存在多媒体系统中,我们只能拿到它的资源地址(url),而不是真实的文件. 这里记录的是下载单个图片.下篇 ...

  9. C++根据图片url下载图片

    需要使用到URLDownloadToFile()函数,该函数在头文件<urlmon.h>中声明. URLDownloadToFile()函数的定义如下: HRESULT URLDownlo ...

随机推荐

  1. Rails框架学习

    Don't Repeat Yourself! Convention Over Configuration. REST. Rails框架总览. Rails框架基本使用. Rails框架数据交互. Rai ...

  2. 图片转tfrecords

    import numpy as np import tensorflow as tf import time import os import cv2 from sklearn.utils impor ...

  3. GIF : 超好用的gif 图片制作工具: LICEcap

    超好用的gif 图片制作工具: LICEcap simple animated screen captures http://www.cockos.com/licecap/https://github ...

  4. LeetCode Binary Search All In One

    LeetCode Binary Search All In One Binary Search 二分查找算法 https://leetcode-cn.com/problems/binary-searc ...

  5. VirtualBox All in One

    VirtualBox All in One 虚拟机 / VM / Virtual Machine x86 and AMD64/Intel64 VirtualBox is a powerful x86 ...

  6. Machine Learning & ML

    Machine Learning & ML https://github.com/Avik-Jain/100-Days-Of-ML-Code https://github.com/MLEver ...

  7. React Hooks in depth

    React Hooks in depth React Hooks https://reactjs.org/docs/hooks-rules.html https://www.npmjs.com/pac ...

  8. serverless & front end

    serverless & front end Cloud Functions or Functions as a Service (FaaS) https://serverless.css-t ...

  9. Axios & POST & application/x-www-form-urlencoded

    Axios & POST & application/x-www-form-urlencoded application/x-www-form-urlencoded https://g ...

  10. macOS & wifi & ip

    macOS & wifi & ip mac show wifi ip # wireless ipconfig getifaddr en1 # ethernet ipconfig get ...