def _downloadFile(self, toDownload):
'''
Downloads the file from the url and saves it in the directory folderPath with the name fileName.
'''
fileName, url = toDownload
# Opens the web page and creates a file in the folder folderPAth and with the name fileName
try:
#===============================================================================
# passman = request.HTTPPasswordMgrWithDefaultRealm()
# passman.add_password(self.realm, url, self.username, self.password)
#
# authhandler = request.HTTPBasicAuthHandler(passman)
# opener = request.build_opener(authhandler)
# request.install_opener(opener)
#===============================================================================
u = request.urlopen(url)
f = open(fileName, 'wb')
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
f.write(buffer)
# Closes the file
f.close()
u.close()
return os.path.getsize(fileName)
except Exception as ex:
warnings.warn(str(ex), UserWarning)
return -1
评论列表
文章目录