python - Pull name for file from array when downloading using urllib -


i trying use urllib library python pull various tools urls stored in array. when go option save them location, name each file after entry in separate array. every time try , run code written here:

import urllib  url = ["http://dw.cbsi.com/redir?ttag=restart_download_click&ptid=3001&pagetype=product_pdl&astid=2&edid=3&tag=link&siteid=4&desturl=&onid=2239&oid=3001-2239_4-10320142&rsid=cbsidownloadcomsite&sl=en&sc=us&topicguid=security%2fantivirus&topicbrcrm=&pid=14314872&mfgid=10044820&merid=10044820&ctype=dm&cval=none&devicetype=desktop&pguid=4ca3cb3823b670cd4386478c&viewguid=v4afv1bqawxd1ku2aku@iehzq6uwztjv6p2f&desturl=http%3a%2f%2fsoftware-files-a.cnet.com%2fs%2fsoftware%2f14%2f31%2f48%2f72%2favg_free_stb_all_5961p1_177.exe%3ftoken%3d1433990253_8690d8cb94b227464de5d6e1d59d78b4%26filename%3davg_free_stb_all_5961p1_177.exe","http://download.piriform.com/ccsetup506.exe"] namelist = ["avg.exe","ccleaner.exe"] x in url , namelist:     urllib.urlretrieve(x, "c:\\users\\myname\\desktop\\"+ namelist[x]) 

i receive error

traceback (most recent call last):   file "p:\pythonprojects\programdownloader.py", line 6, in <module>     urllib.urlretrieve(x, "c:\\users\\myname\\desktop\\"+ namelist[x]) typeerror: list indices must integers, not str 

can me this?

zip lists if want match corresponding elements each list unpack in loop:

url = ["http://dw.cbsi.com/redir?ttag=restart_download_click&ptid=3001&pagetype=product_pdl&astid=2&edid=3&tag=link&siteid=4&desturl=&onid=2239&oid=3001-2239_4-10320142&rsid=cbsidownloadcomsite&sl=en&sc=us&topicguid=security%2fantivirus&topicbrcrm=&pid=14314872&mfgid=10044820&merid=10044820&ctype=dm&cval=none&devicetype=desktop&pguid=4ca3cb3823b670cd4386478c&viewguid=v4afv1bqawxd1ku2aku@iehzq6uwztjv6p2f&desturl=http%3a%2f%2fsoftware-files-a.cnet.com%2fs%2fsoftware%2f14%2f31%2f48%2f72%2favg_free_stb_all_5961p1_177.exe%3ftoken%3d1433990253_8690d8cb94b227464de5d6e1d59d78b4%26filename%3davg_free_stb_all_5961p1_177.exe","http://download.piriform.com/ccsetup506.exe"] namelist = ["avg.exe","ccleaner.exe"] x, name in zip(url,namelist):     urllib.urlretrieve(x, "c:\\users\\myname\\desktop\\"+ name) 

you trying index namelist string x each string namelist i.e namelist["avg.exe"], why code errors.

if wanted index need enumerate:

for ind, x in enumerate(url):     urllib.urlretrieve(x, "c:\\users\\myname\\desktop\\"+ namelist[ind]) 

where ind index of each element in url list.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -