Can a file be downloaded from url using python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can a file be downloaded from url using python

i want to download a ile from url

12th Jan 2017, 11:01 AM
manoj
7 Answers
+ 4
Why python when you can use your browser?
12th Jan 2017, 11:16 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 3
or maybe he wants to code a simple downloader with python
12th Jan 2017, 1:01 PM
Minovsky
Minovsky - avatar
+ 2
because he wants the user to input something in python and get the info he needs from the browser maybe?
12th Jan 2017, 12:29 PM
ramzi
ramzi - avatar
14th Jan 2017, 1:09 AM
edoardo
+ 2
#Try this code . # python geturl.py http://example.com/downloads/bigfile.zip # from http://code.activestate.com/recipes/576530-download-a-url-with-a-console-progress-meter/ import os, sys, urllib def _reporthook(numblocks, blocksize, filesize, url=None): #print ("reporthook(%s, %s, %s)" % (numblocks, blocksize, filesize)) base = os.path.basename(url) #XXX Should handle possible filesize=-1. try: percent = min((numblocks*blocksize*100)/filesize, 100) except: percent = 100 if numblocks != 0: sys.stdout.write("\b"*70) sys.stdout.write("%-66s%3d%%" % (base, percent)) def geturl(url, dst): print ("get url '%s' to '%s'" % (url, dst)) if sys.stdout.isatty(): urllib.urlretrieve(url, dst, lambda nb, bs, fs, url=url: _reporthook(nb,bs,fs,url)) sys.stdout.write('\n') else: urllib.urlretrieve(url, dst) if __name__ == "__main__": if len(sys.argv) == 2: url = sys.argv[1] base = url[url.rindex('/')+1:] geturl(url, base) elif len(sys.argv) == 3: url, base = sys.argv[1:] geturl(url, base) else: print ("Usage: geturl.py URL [DEST]") sys.exit(1)
14th Jan 2017, 7:15 AM
Minovsky
Minovsky - avatar
+ 2
# This one may be useful too #http://sametmax.com/peut-on-compiler-un-programme-JUMP_LINK__&&__python__&&__JUMP_LINK/ import requests import docopt u title = parse(p).getroot().find('head').find('title').text print('Downloaded "%s"' % title)
14th Jan 2017, 7:51 AM
Minovsky
Minovsky - avatar
0
可以
12th Jan 2017, 5:27 PM
tang sir