Skip to content

Instantly share code, notes, and snippets.

@abolibibelot
Last active December 11, 2015 21:58
Show Gist options
  • Save abolibibelot/4665859 to your computer and use it in GitHub Desktop.
Save abolibibelot/4665859 to your computer and use it in GitHub Desktop.
requests API >= 0.13.6 mandates passing prefetch=False when accessing the raw response as a file like object... (see https://github.com/kennethreitz/requests/issues/825 )
import requests
import re
import os
import sys
def getFile( id ):
url = 'http://dl.free.fr/%s' % id
# get initial link
r = requests.get(url)
contents = r.content
href = re.findall(r'href="([^"]+)">Télécharger ce fichier', contents )[0]
filename = os.path.basename( href )
cookies = r.cookies
# start download
print "downloading", filename
download = requests.get(href, cookies = cookies, prefetch=False).raw
CHUNK = 64 * 1024
with open(filename, 'wb') as fp:
while True:
print '.',
sys.stdout.flush().
chunk = download.read(CHUNK)
if not chunk: break
fp.write(chunk)
if __name__ == '__main__':
if len(sys.argv)>1:
getFile( sys.argv[1] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment