python - How can I download images from a list of links? -


i have list of links images (about 5000 lines), , need know how can download fast. please me code:

import concurrent.futures import urllib.request  catname = 'amateur'  def getimg (count, endcount):     while (count < endcount):       urllib.request.urlretrieve(urls[count], catname+'/images/'+catname+str(count)+'.jpg')       urls[count] = catname+'/images/'+catname+str(count)+'.jpg'       count = count + 1  concurrent.futures.threadpoolexecutor(max_workers=50) e:     e.submit(getimg, 0, 5000) 

it works fine slow.

your code download 5000 images 50 times. try following:

import concurrent.futures import urllib.request  catname = 'amateur'  def getimg(count):     localpath = '{0}/images/{0}{1}.jpg'.format(catname, count)     urllib.request.urlretrieve(urls[count], localpath)     urls[count] = localpath  concurrent.futures.threadpoolexecutor(max_workers=50) e:     in range(5000):         e.submit(getimg, i) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -