When I use either the
$: wget -P "test" http://www.google.com/intl/en_com/images/srpr/logo3w.png
Saving to: `test/logo3w.png'
$: wget -O "google.png" http://www.google.com/intl/en_com/images/srpr/logo3w.png
2012-01-23 21:47:33 (1.20 MB/s) - `google.png' saved [7007/7007]
$: wget -P "test" -O "google.png" http://www.google.com/intl/en_com/images/srpr/logo3w.png
2012-01-23 21:47:51 (5.87 MB/s) - `google.png' saved [7007/7007]
Popen(['wget', '-O', file, theImg], stdout=PIPE, stderr=STDOUT)
DEBUG output created by Wget 1.13.4 on darwin10.8.0.
You should just pass
import subprocess import os.path subprocess.Popen(['wget', '-O', os.path.join(directory, filename), theImg])
It's not completely clear from your question whether you were already doing something similar to this, but if you were and it still failed, I can think of two reasons:
The argument to
-O contains a leading
wget fail because it doesn't have permission to randomly create directories in
The directory you're telling
wget to write to doesn't exist. You can make sure it exists by creating it first using
os.mkdir in the Python standard library.
You can also try removing the arguments
stderr= from the
Popen call so you can see the errors directly, or print them using Python.