代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Python
】
简单的批量下载工具
作者:
Darren_Chan
/ 发布于
2013/8/5
/
884
#!/usr/bin/python # -*- coding: utf-8 -*- import sys, os import urllib.request ''' Author: Bouygues Date: 4th August, 2013 Version: 1.1 Update Logs: version 1.0: created version 1.1: add try ... catch for HttpError handling version 1.2: can save file to disk by chunk ''' # --- class --- class MultiDownload(): ''' download urls in list, ignore one not in self.pfix save each name according to its url name; save them into directory fold; ''' def __init__(self, urls, fold): self.urls = urls self.fold = self.pathFormat(fold) # download by chunk self.chunk = 512 self.pfix = ("jpg", "JPG", "JPEG", "jpeg", "png", "PNG") def pathFormat(self, path): """ make sure the path is a right directory path; and end with '/' """ path = path.strip() path = path.replace("\\", "/") size = len(path) if(path[size-1]!="/"): path += "/" return path def getPostfix(self, url): if "." not in url: return None p = url.rfind(".") + 1 return url[p:] def getFileName(self, url): if "/" not in url: return None p = url.rfind("/") + 1 return url[p:] def down(self, url): filename = self.getFileName(url) path = self.fold + filename f = open(path, 'wb') try: w = urllib.request.urlopen(url) except: print("[ERROR] %s" % (url)) else: # save file by chunk (if file size is too big) while True: chunkD = w.read(self.chunk*1024) if len(chunkD)==0 : break f.write(chunkD) print(" - Download %dK data" % (len(chunkD)/1024)) #data = w.read() #f.write(data) w.close() finally: f.close() def run(self): for line in self.urls: #if self.getPostfix(line) not in self.pfix: # continue self.down(line) print(line) return True # --- global functions --- # --- main --- ''' download files listed in file ''' # variables inputfile = input("input filename: ") targetList = set() basedir = input("where do you want to save files? ") # get url list f = open(inputfile, 'r') for line in f: line = line.strip() if len(line)>3: targetList.add(line) f.close() # download each file md = MultiDownload(targetList, basedir) md.run()
试试其它关键字
批量下载
同语言下
.
比较两个图片的相似度
.
过urllib2获取带有中文参数的url内容
.
不下载获取远程图片的宽度和高度及文件大小
.
通过qrcode库生成二维码
.
通过httplib发送GET和POST请求
.
Django下解决小文件下载
.
遍历windows的所有窗口并输出窗口标题
.
根据窗口标题调用窗口
.
python 抓取搜狗指定公众号
.
pandas读取指定列
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Darren_Chan
贡献的其它代码
(
1
)
.
简单的批量下载工具
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3