imgurl1 = ['https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRBq9ME-DAgKNLb_pf4BuLIPesmc2dU_FXR_1Pr52exF1P7y8Sv',
'https://encrypted-tbn0.gstatic.com/images? q=tbn:ANd9GcQAhCI45WjeZ1tTq5h7dB3lyBAwk7BuayfMJC2aUVsq-GUgpn3eSA',
Five image URL addresses.
a = ['aa','bb','cc','dd','ee']
def fetch_detail_url():
b = 0
for p in imgurl1:
for v in a:
urllib.request.urlretrieve(p, "c:/data/" + str(v) +str(b) + ".jpg" )
b = b + 1
if b == int(len(imgurl1)):
break
fetch_detail_url()
I want to run the above function to make five image files I want to make only 5 files with the names aa1, bb2, cc3, dd4, ee5.
It's not working. Python beginner, please ㅠ<
python
I created it under the assumption that there are two files.
Just keep that in mind.
In [16]: import urllib.request as request
In [17]: fileURLs = ('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRBq9ME-DAgKNLb_pf4BuLIPesmc2dU_FXR_1Pr52exF1P7y8Sv','https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRRo3WzmJo3VnwIJ6wRts3gfyvTAUz4zBNWVMRQeMN
: : mUSQrbArB')
In [18]: a = ['aa','bb']
In [19]: URLMap = zip(fileURLs, a)
In [20]: list(map(lambda item:request.urlretrieve(item[0], "{0}.jpg".format(item[1])), URLMap))
Out[20]:
[('aa.jpg', <http.client.HTTPMessage at 0x7f6b316e44e0>),
('bb.jpg', <http.client.HTTPMessage at 0x7f6b316e4240>)]
© 2024 OneMinuteCode. All rights reserved.