Python: 从 指定地址 下载文件 到 本地目录(附源码)
来源:互联网 发布:淘宝收藏修改分类 编辑:程序博客网 时间:2024/05/22 13:38
# -*- coding: utf-8 -*-import osimport urllibimport loggingimport syslogging.basicConfig( format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO, stream=sys.stdout)file_path = os.path.join(os.getcwd(),'dir_name/file_name')if not os.path.isfile(file_path): logging.info("File doesn't exist.") # replace with url you need url = '网络指定地址' # if dir 'dir_name/' doesn't exist file_dir = file_path[:-9] if not os.path.exists(file_dir): logging.info("Mkdir 'dir_name/'.") os.mkdir(file_dir) def down(_save_path, _url): try: urllib.urlretrieve(_url, _save_path) except: print '\nError when retrieving the URL:', _save_path logging.info("Downloading file.") down(file_path, url)else: logging.info("File exists.")
后面我会上传源代码文件托管至CSDN。
阅读全文
0 0
- Python: 从 指定地址 下载文件 到 本地目录(附源码)
- 以命令方式从FTP 服务器下载文件到本地指定目录
- 以命令方式从FTP 服务器下载文件到本地指定目录
- 从ftp下载指定文件到指定的目录
- C# Http地址下载文件到指定目录。
- java浏览器文件下载实例(附源码下载地址)
- python urllib从远程服务器下载文件到本地
- python urllib从远程服务器下载文件到本地
- python爬虫-下载图片到本地目录
- android 将文件下载到指定目录
- python 从共享文件中自动拷贝指定文件到本地
- python 从共享文件中自动拷贝指定文件到本地【续】
- Linux从Ftp上下载最新文件,并保存到指定目录(实现有点2--)
- python 从指定目录获取文件
- 如何从网络下载文件到本地
- Java 从服务器下载文件到本地
- Java 从服务器下载文件到本地
- JAVA从网络下载文件到本地
- pdo 连接mysql 出现数据类型不一致问题(即全等问题)
- 十五天精通WCF——第十天 学会用SvcConfigEditor来简化配置
- 实现二元信号量对屏幕保护
- 洛谷Oj-Likecloud-吃、吃、吃-多维动态规划
- LeetCode #19 Remove Nth Node From End of List
- Python: 从 指定地址 下载文件 到 本地目录(附源码)
- 《深入理解java虚拟机》学习笔记8——Tomcat类加载器体系结构
- RHEL7 切换字符编码为GBK
- 快速搭建多终端同步的 github + hexo 静态博客
- Mongo修改数据类型
- php数据类型
- 从控制台输入项目路径输出java到本地txt
- Android MVP架构思考初稿
- 人脸检测之基于Opencv和MFC创作的换脸小程序