批量下载RFC文档(python实现)
2012-01-20 15:05
931 查看
RFC文档有很多,有时候在没有联网的情况下也想翻阅,只能下载一份留存本地了。
看了看地址列表,大概是这个范围: http://www.networksorcery.com/enp/rfc/rfc1000.txt ... http://www.networksorcery.com/enp/rfc/rfc6409.txt
哈哈,很适合批量下载,第一个想到的就是迅雷……
可用的时候发现它只支持三位数的扩展(用的是迅雷7),我想要下的刚好是四位数……
郁闷之下萌生自己做一个的想法!
这东西很适合用python做,原理很简单,代码也很少,先读为快。
代码如下:
除了RFC文档,这个程序稍加修改也可以做其它事情:比如批量下载MP3、电子书等等。
好,就这些了,希望对你有帮助。
看了看地址列表,大概是这个范围: http://www.networksorcery.com/enp/rfc/rfc1000.txt ... http://www.networksorcery.com/enp/rfc/rfc6409.txt
哈哈,很适合批量下载,第一个想到的就是迅雷……
可用的时候发现它只支持三位数的扩展(用的是迅雷7),我想要下的刚好是四位数……
郁闷之下萌生自己做一个的想法!
这东西很适合用python做,原理很简单,代码也很少,先读为快。
代码如下:
#! /usr/bin/python ''' File : getRFC.py Author : Mike E-Mail : Mike_Zhang@live.com ''' import urllib,os,shutil,time def downloadHtmlPage(url,tmpf = ''): i = url.rfind('/') fileName = url[i+1:] if tmpf : fileName = tmpf print url,"->",fileName urllib.urlretrieve(url,fileName) print 'Downloaded ',fileName time.sleep(0.2) return fileName # http://www.networksorcery.com/enp/rfc/rfc1000.txt # http://www.networksorcery.com/enp/rfc/rfc6409.txt if __name__ == '__main__': addr = 'http://www.networksorcery.com/enp/rfc' dirPath = "RFC" #startIndex = 1000 startIndex = int(raw_input('start : ')) #endIndex = 6409 endIndex = int(raw_input('end : ')) if startIndex > endIndex : print 'Input error!' if False == os.path.exists(dirPath): os.makedirs(dirPath) fileDownloadList = [] logFile = open("log.txt","w") for i in range(startIndex,endIndex+1): try: t_url = '%s/rfc%d.txt' % (addr,i) fileName = downloadHtmlPage(t_url) oldName = './'+fileName newName = './'+dirPath+'/'+fileName if True == os.path.exists(oldName): shutil.move(oldName,newName) print 'Moved ',oldName,' to ',newName except: msgLog = 'get %s failed!' % (i) print msgLog logFile.write(msgLog+'\n') continue logFile.close()
除了RFC文档,这个程序稍加修改也可以做其它事情:比如批量下载MP3、电子书等等。
好,就这些了,希望对你有帮助。
相关文章推荐
- 批量下载RFC文档(python实现)
- Python实现的批量下载RFC文档
- Python实现的批量下载RFC文档
- python实现抖音视频批量下载
- python实现网站内部视频批量下载
- Python实现Youku视频批量下载功能
- SharePoint 2010 自定义Ribbon实现文档批量下载为Zip文件
- CSDN博客专栏文章批量下载脚本[python实现]
- Python使用扩展库pywin32实现批量文档打印
- CSDN博客专栏文章批量下载脚本[python实现]
- Python实现简单爬虫功能--批量下载百度贴吧里的图片
- 利用Python脚本实现-----登陆新浪微博&批量下载收藏内容
- springMvcZip下载 压缩流实现批量下载Word文档
- 用Python 爬虫批量下载PDF文档
- SharePoint 2010 自定义Ribbon实现文档批量下载为Zip文件[转]
- python实现批量下载贴吧图片
- python实现蜘蛛功能批量下载手机壁纸
- SharePoint 2010文档库批量下载文档的实现
- SharePoint 2010 自定义Ribbon实现文档批量下载为Zip文件