PYTHON code questions.

Asked 2 years ago, Updated 2 years ago, 42 views

imgurl1 = ['https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRBq9ME-DAgKNLb_pf4BuLIPesmc2dU_FXR_1Pr52exF1P7y8Sv',

'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRRo3WzmJo3VnwIJ6wRts3gfyvTAUz4zBNWVMRQeMNmUSQrbArB',

'https://encrypted-tbn0.gstatic.com/images? q=tbn:ANd9GcQAhCI45WjeZ1tTq5h7dB3lyBAwk7BuayfMJC2aUVsq-GUgpn3eSA',

'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTD1uWdMyuwYtMlr0spdMhgCtGj9IBpwveAtnUa0DkDSnIMemoj1g',

'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRBTjVkUYBYpq0tKwy4o-CYcEf7zuSalgl-u1Y-DuYS5B3N3ipMsA']

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

2022-09-22 13:33

1 Answers

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>)]


2022-09-22 13:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.