使用Python保存下载的ZIP文件

使用Python保存下载的ZIP文件,第1张

概述我正在编写一个脚本,它将自动更新已安装的Calibre版本.目前我已经下载了最新的便携版本.我似乎无法保存zipfile.目前我的代码是: import urllib2import reimport zipfile#tell the user what is happeningprint("Calibre is Updating")#download the pageurl = u 我正在编写一个脚本,它将自动更新已安装的Calibre版本.目前我已经下载了最新的便携版本.我似乎无法保存zipfile.目前我的代码是:

import urllib2import reimport zipfile#tell the user what is happeningprint("Calibre is Updating")#download the pageurl = urllib2.urlopen ( "http://sourceforge.net/projects/calibre/files" ).read()#determin current versionresult = re.search('title="/[0-9.]*/([a-zA-Z\-]*-[0-9\.]*)',url).groups()[0][:-1]#download filedownload = "http://status.calibre-ebook.com/dist/portable/" + resulturllib2.urlopen( download )#saveoutput = open('install.zip','w')output.write(zipfile.Zipfile("install.zip",""))output.close()
解决方法 你不需要为此使用zipfile.Zipfile(以及你使用它的方式,以及urllib2.urlopen也有问题).相反,您需要将urlopen结果保存在变量中,然后读取它并将该输出写入.zip文件.试试这段代码:

#download filedownload = "http://status.calibre-ebook.com/dist/portable/" + resultrequest = urllib2.urlopen( download )#saveoutput = open("install.zip","w")output.write(request.read())output.close()
总结

以上是内存溢出为你收集整理的使用Python保存下载的ZIP文件全部内容,希望文章能够帮你解决使用Python保存下载的ZIP文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1194532.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存