第一次写文章,界面不太好看,还请见谅。
#######################################################################
虽然ASF网站提供了python批下载的脚本,但是不知道是由于网络原因还是我的python脚本不对,下载经常中断,有时候甚至运行了一天一个文件也没有下下来,一个一个的手动下载又太麻烦。所以使用IDM下载器进行批量下载。
这里面的第一个问题是url链接,我们直接输入python脚本中的链接是无法运行的,需要修改download_file_with_cookiejar函数,我修改后的代码如下:(将test打印的列表放到IDM)

 def download_file_with_cookiejar(self, url, file_count, total, recursion=False):test=[]# see if we've already download this file and if it is that it is the correct sizedownload_file = os.path.basename(url).split('?')[0]if os.path.isfile(download_file):try:request = Request(url)request.get_method = lambda : 'HEAD'response = urlopen(request, timeout=30)remote_size = self.get_total_size(response)# Check that we were able to derive a size.if remote_size:local_size = os.path.getsize(download_file)if remote_size < (local_size+(local_size*.01)) and remote_size > (local_size-(local_size*.01)):print (" > Download file {0} exists! \n > Skipping download of {1}. ".format(download_file, url))return None,None#partial file size wasn't full file size, lets blow away the chunk and start againprint (" > Found {0} but it wasn't fully downloaded. Removing file and downloading again.".format(download_file))os.remove(download_file)except ssl.CertificateError as e:print (" > ERROR: {0}".format(e))print (" > Could not validate SSL Cert. You may be able to overcome this using the --insecure flag")return False,Noneexcept HTTPError as e:if e.code == 401:print (" > IMPORTANT: Your user may not have permission to download this type of data!")else:print (" > Unknown Error, Could not get file HEAD: {0}".format(e))except URLError as e:print ("URL Error (from HEAD): {0}, {1}".format( e.reason, url))if "ssl.c" in "{0}".format(e.reason):print ("IMPORTANT: Remote location may not be accepting your SSL configuration. This is a terminal error.")return False,Nonefor url in self.files:# attempt https connectiontry:request = Request(url)response = urlopen(request, timeout=30)# Watch for redirectif response.geturl() != url:# See if we were redirect BACK to URS for re-auth.if 'https://urs.earthdata.nasa.gov/oauth/authorize' in response.geturl():if recursion:print (" > Entering seemingly endless auth loop. Aborting. ")return False, None# make this easier. If there is no app_type=401, add itnew_auth_url = response.geturl()print("lalalalal")print(new_auth_url)if "app_type" not in new_auth_url:new_auth_url += "&app_type=401"print (" > While attempting to download {0}....".format(url))print (" > Need to obtain new cookie from {0}".format(new_auth_url))old_cookies = [cookie.name for cookie in self.cookie_jar]opener = build_opener(HTTPCookieProcessor(self.cookie_jar), HTTPHandler(), HTTPSHandler(**self.context))request = Request(new_auth_url)try:response = opener.open(request)for cookie in self.cookie_jar:if cookie.name not in old_cookies:print (" > Saved new cookie: {0}".format(cookie.name))# A little hack to save session cookiesif cookie.discard:cookie.expires = int(time.time()) + 60*60*24*30print (" > Saving session Cookie that should have been discarded! ")#self.cookie_jar.save(self.cookie_jar_path, ignore_discard=True, ignore_expires=True)except HTTPError as e:print ("HTTP Error: {0}, {1}".format( e.code, url))return False,None# Okay, now we have more cookies! Lets try again, recursively!print (" > Attempting download again with new cookies!")return self.download_file_with_cookiejar(url, file_count, total, recursion=True)print (" > 'Temporary' Redirect download @ Remote archive:\n > {0}".format(response.geturl()))test.append(response.geturl())print(test)# seems to be working#print ("({0}/{1}) Downloading {2}".format(file_count, total, url))# Open our local file for writing and build status bar# tf = tempfile.NamedTemporaryFile(mode='w+b', delete=False, dir='.')# self.chunk_read(response, tf, report_hook=self.chunk_report)## # Reset download status# sys.stdout.write('\n')## tempfile_name = tf.name# tf.close()#handle errorsexcept HTTPError as e:# print ("HTTP Error: {0}, {1}".format( e.code, url))## if e.code == 401:#    print (" > IMPORTANT: Your user does not have permission to download this type of data!")## if e.code == 403:#    print (" > Got a 403 Error trying to download this file.  ")#    print (" > You MAY need to log in this app and agree to a EULA. ")#return

然后就可以啦!!
新人求关注!

IDM下载ASF文件相关推荐

  1. idm如何下载种子文件和磁力链接 idm如何下载torrent

    采用分段式下载技术并支持断点续传的idm下载加速器,几乎可以胜任所有的下载任务.由于该软件强大的下载能力和仅为10MB的小巧体积,idm被来自全球的用户亲切地称为天花板级的下载软件.那么有关idm如何 ...

  2. 可用迅雷或idm下载百度云文件的新方法

    之前介绍了类似的方法去下载百度云文件(看这里),但大文件的下载的确是个难题.有句话说的好,办法总比困难多嘛.所以我苦苦寻找又发现了某个集idm.迅雷.xdown综合下载的新脚本,关键是不限制下载文件大 ...

  3. idm文件夹无法删除 idm可以下载什么文件

    IDM功能强大.界面简洁.操作简单,不仅能够无缝集成到主流的浏览器中,还支持下载加速.队列处理等功能,是一款不可多得的下载加速器.有些朋友由于对这款软件不太熟悉,导致在操作时遇到了一些问题,如idm文 ...

  4. idm下载器如何使用 idm下载器使用技巧

    idm下载器一直被称为下载神器,不仅是因为它的多线程下载模式能大幅提高资源下载速度,更多的是idm能安装插件.嗅探网页资源并下载,比如一些网页视频.音频等等,具体idm下载如何使用呢?下面告诉大家几个 ...

  5. IDM下载百度网盘教程

    前提条件:Google浏览器,IDM插件,油猴插件(tampermonkey) 1.安装IDM和tampermonkey 2.进入脚本网站下载脚本:https://greasyfork.org/zh- ...

  6. IDM下载百度云资源

    百度云限速很难受,不过破解的方法也很多.工具可以直接下载pandownload.速盘.ENFI下载器 一.安装IDM IDM(PC端下载) -Chrome浏览器插件 安装好后可能需要更新, 更新完成后 ...

  7. 多个使用idm下载器的技巧和窍门.

    如果使用了本文提供的技巧.你无疑可以将idm下载器的下载速度从一般情况的5倍提高到惊人的8倍! 1. IDM是当今互联网上最好的下载器. 2. 就功能而言,它比任何下载管理器都要好. 3. 下面,我们 ...

  8. Google drive谷歌网盘下载副本文件无法调用IDM解决方法

    最近通过加入星标并复制产生副本文件来解决谷歌限制文件大小时,遇到了Google drive谷歌网盘下载副本文件无法调用IDM来进行下载,只能够使用浏览器直接下载. 但是直接下载原文件没有出现问题,可以 ...

  9. idm 服务器响应显示您没有权限下载此文件_仅需10分钟,让你掌握下载神器IDM的使用技巧...

    在之前分享过解除百度网盘限速的文章中,IDM 是不可或缺的一个环节,IDM 除了可以用来加速下载百度网盘资源外,其本身也是一款非常强大的下载器. 关于IDM下载器 Internet Download ...

最新文章

  1. 360加固分析(一)
  2. ios retain 与 copy 的区别
  3. Mono,CLR,.net,Net Framework之间的关系
  4. [js] 说说防止重复发送ajax请求的方法有哪些?各自有什么优缺点?
  5. dede plus ad js.php,织梦程序中plus文件作用介绍及安全设置
  6. 浏览器和服务器交互原理?(请求--响应的过程)
  7. IntelliJ IDEA 中文官方文档
  8. Pycharm Professional(专业版2018.2.1)最简单方法破解,亲测有效(转)
  9. STC学习:便携式温度采集器
  10. 华为android9使用外置存储卡,华为mate9如何删除内存卡文件?华为手机清理内存教程...
  11. 街机游戏模拟器 mame for linux
  12. 蚂蚁市场教程:电视安装看B站(哔哩哔哩)TV版
  13. 使用百度大脑构建一个闲聊机器人
  14. python股票网格交易法详解_我的选股方法 大家好,我是阿兰,一个将网格交易法应用于股票的人。昨天我给大家介绍了我的网格交易体系,并简单说明了我的选股方法,今天我将... - 雪球...
  15. 可能是国内第一篇全面解读Java现状及趋势的文章
  16. HTML5笔记Day_01注释;标签;特殊符号;块元素和行内元素
  17. 「数据游戏」:使用 ARIMA 算法预测三日后招商银行收盘价
  18. 牧牛商学院,区块链技术在会计领域的应用
  19. Unity 警告 Tiled GPU perf. warning: RenderTexture color surface (110x82) was not cleared/discarded
  20. vb.net 教程 3-2 窗体编程之窗体 5

热门文章

  1. 快速教会你电脑怎么做思维导图,仅需借助这几款思维导图制作软件
  2. java连接海康摄像头_Java实现 海康摄像头抓拍图像
  3. Ubuntu18.04 安装Asterisk16.10 + FreePBX15.0
  4. 【小白】第一天学习笔记:交换机、路由器
  5. Overture5.5.3 官方版下载— 钢琴打谱软件
  6. 博奥智源公司分享麻醉药品管理系统功能设计模块
  7. AD09 DXP保姆级教程系列——006、PCB布局、走线方法和设计原则基础
  8. 卖二手车能挣多少钱?
  9. HTML中 div标签内背景图片自适应div大小
  10. Python中的基本语法2