To answer your direct question, like the others, you should seriously consider using the subprocess module. Here is an example:
from subprocess import Popen, PIPE, STDOUT wget = Popen(['/usr/bin/wget', theurl], stdout=PIPE, stderr=STDOUT) stdout, nothing = wget.communicate() with open('wget.log', 'w') as wgetlog: wgetlog.write(stdout)
But you do not need to call the system to download the file, let python do the hard work for you.
Using urllib ,
try: # python 2.x from urllib import urlretrieve except ImportError: # python 3.x from urllib.request import urlretrieve urlretrieve(theurl, local_filename)
Or urllib2 ,
import urllib2 response = urllib2.urlopen(theurl) with open(local_filename, 'w') as dl: dl.write(response.read())
local_filename is the destination path of your choice. Sometimes this can be determined automatically, but the approach depends on your circumstances.
Marty
source share