我有一些圖片的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
的非常好的和強大的功能感謝你們兩個......我明白我的錯誤,並找到一個工作代碼.... –