Nessun motivo per utilizzare os.system. Evita di scrivere uno script di shell in Python e vai con qualcosa come urllib.urlretrieve o un equivalente.
Modifica ... per rispondere alla seconda parte della domanda, è possibile impostare un pool di thread utilizzando la classe Coda della libreria standard. Dato che stai facendo un sacco di download, GIL non dovrebbe essere un problema. Genera un elenco degli URL che desideri scaricare e inseriscili nella tua coda di lavoro. Gestirà le richieste di push ai thread dei lavoratori.
Sto aspettando il completamento di un aggiornamento del database, quindi l'ho messo insieme molto rapidamente.
#!/usr/bin/python
import sys
import threading
import urllib
from Queue import Queue
import logging
class Downloader(threading.Thread):
def __init__(self, queue):
super(Downloader, self).__init__()
self.queue = queue
def run(self):
while True:
download_url, save_as = queue.get()
# sentinal
if not download_url:
return
try:
urllib.urlretrieve(download_url, filename=save_as)
except Exception, e:
logging.warn("error downloading %s: %s" % (download_url, e))
if __name__ == '__main__':
queue = Queue()
threads = []
for i in xrange(5):
threads.append(Downloader(queue))
threads[-1].start()
for line in sys.stdin:
url = line.strip()
filename = url.split('/')[-1]
print "Download %s as %s" % (url, filename)
queue.put((url, filename))
# if we get here, stdin has gotten the ^D
print "Finishing current downloads"
for i in xrange(5):
queue.put((None, None))
Come lo faresti? Prima cerca tutte le domande precedenti esattamente come la tua: http://stackoverflow.com/questions/tagged/wget+python. In secondo luogo, leggi questa domanda specifica: http://stackoverflow.com/questions/419235/anyone-know-of-a-good-python-based-web-crawler-that-i-could-use –