Python: 从 指定地址 下载文件 到 本地目录(附源码)
2017-06-27 17:08
453 查看
# -*- coding: utf-8 -*- import os import urllib import logging import sys logging.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。
相关文章推荐
- 以命令方式从FTP 服务器下载文件到本地指定目录
- 爪哇国新游记之二十八----从url指定的地址下载文件到本地
- php带密码功能并下载远程文件保存本地指定目录 修改加强版
- php带密码功能并下载远程文件保存本地指定目录 修改加强版
- C# Http地址下载文件到指定目录。
- 以命令方式从FTP 服务器下载文件到本地指定目录
- 新手学Python 删除指定目录下的所有文件
- asp.net(c#)从url网络地址下载图片或文件到本地硬盘
- Linux输入文件名从FTP 指定目录下载 文件
- 在使用SVN,下载文件到本地时,一定要把全目录下载下来!
- 弹出另存为窗口下载指定目录的文件
- python输出指定目录下所有文件(全路径),并核对md5码
- PYTHON 列出指定目录下的文件
- 保存指定文件夹下的目录和文件名到文件中 Python 脚本
- 在Asp.net中如何遍历一个本地目录下的所有文件并上载到Web 服务器上指定的目录中
- applet将服务器上文件下载到本机指定目录下 求解
- 源码--删除指定目录下(包含子目录)的文件
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
- ftp自动登录下载文件到指定目录
- 给定ftp地址、user、pw下载根目录下的所有PE文件???