我有一些图片的URL列表,我想下载它们 进口的urllibPython2.7如何循环的urllib下载图像
links = ['http://www.takamine.com/templates/default/images/gclassical.png',
'https://dk1xgl0d43mu1.cloudfront.net/user_files/esp/product_images/000/010/120/large.png?1389980652',
'https://dk1xgl0d43mu1.cloudfront.net/user_files/esp/product_images/000/020/676/large.png?1453396324']
#urllib.urlretrieve('http://www.takamine.com/templates/default/images/gclassical.png','image.jpg')
for i in range(0,4):
S1 = 'image'
S2 = '.png'
name = list()
x = S1 + str(i) + S2
name.append(x)
for q in links:
urllib.urlretrieve(q,name)
我明白了如何检索一次一个...... 。当我尝试此代码,我得到这个错误
Traceback (most recent call last): File "C:/Python27/metal memes/test1.py", line 17, in urllib.urlretrieve(q,name) File "C:\Python27\lib\urllib.py", line 98, in urlretrieve return opener.retrieve(url, filename, reporthook, data) File "C:\Python27\lib\urllib.py", line 249, in retrieve tfp = open(filename, 'wb') TypeError: coercing to Unicode: need string or buffer, list found
任何答案,解释赞赏
顺便说一句,'名= [ “图像{}。PNG” .format(x)的有效范围内的X(4)]' –
感谢@ cricket_007,列表解析是蟒 – jps
的非常好的和强大的功能感谢你们两个......我明白我的错误,并找到一个工作代码.... –