Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Download multiple images and rename them
Morning guys, I'm trying to download pictures and rename them

I've got 1 product, that has 5 pictures, so 5 pictures to download and rename.

It would look something like :
(full url to download -

url = [''] # url is always the same, the name of the of the picture chances always (it's a product name)

old filename = "AMDBNBW-1.jpg" (there's 5 pictures always, so AMDBNBW-2.jpg, AMDBNBW-3.jpg, AMDBNBW-4.jpg, AMDBNBW-5.jpg )
new filename = "FRIDAY-1.jpg" also renamed sequantially from 1 to 5.jpg

I need to rename the AMDBNBW-1.jpg, to something like "FRIDAY-1.jpg", "FRIDAY-2.jpg", "FRIDAY-3.jpg", "FRIDAY-4.jpg", "FRIDAY-5.jpg"

Please help me to solve this. Thank you in advance
You should always show results of your effort! It is not very nice to ask help without spending your own time in trying to solve your problem.

Desired result can be achieved:

import urllib.request

for x in range(1, 6):
    website = f'{x}.jpg'
    filename = f'FRIDAY-{x}.jpg'
    urllib.request.urlretrieve(website, filename)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Life of Brian: Conjugate the verb, "to go" !
Thank you @Perfringo ! My initial code using wget is located here :

How do deal when u have multiple product codes ?
It depends. If you have list of product codes, pictures are in same location and there is always same number of photos then you just add additional layer for looping, something like that (incomplete snippet):


for sku in skus:
    for x in range(1, 6):
        website = f'{sku}-{x}.jpg'
If there are several product codes issue of naming downloaded files must be solved. Once again, it depends what do you have. If you have list of desired filenames then you can match them with zip:

names = ['FRIDAY', 'SATURDAY', 'SUNDAY']

for sku, name in zip(skus, names):
    for x in range(1, 6):
        website = f'{sku}-{x}.jpg'
        filename = f'{name}-{x}.jpg'
        urllib.request.urlretrieve(website, filename)
If there is no lists and required data must be entered manually then it makes sense to write it in suitable format right away:


Then for-loop becomes:

for sku, name in record:

If there is variable number of product pictures then you set range to maximum possible pictures and use try... except to catch HTPPError and break out from loop.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Life of Brian: Conjugate the verb, "to go" !
Thank you guys ! You know you're great !

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Issue with os.rename malinowy 4 216 Jul-01-2019, 11:53 AM
Last Post: malinowy
  o365 special subject mail download issue anna 3 219 May-16-2019, 07:16 PM
Last Post: micseydel
  Openpyxl - When save existing xlsx sheet, images/drawing does not get saved shubhamjainj 2 389 Apr-16-2019, 07:09 AM
Last Post: shubhamjainj
  Putting text on images from excel/csv file sam77am 1 212 Apr-05-2019, 07:36 AM
Last Post: Larz60+
  Mass load images Linuxdesire 1 206 Mar-29-2019, 06:24 PM
Last Post: Larz60+
  Automate the calculus of NDVI index on a 100 images yassine01 0 166 Mar-27-2019, 12:13 PM
Last Post: yassine01
  How to get python to download YouTube videos in the background? Pythenx 11 736 Mar-25-2019, 04:57 AM
Last Post: samsonite
  Scanning files to rename other files in the same folder. msd1391 6 433 Mar-11-2019, 07:19 PM
Last Post: msd1391
  rename many pdf'S in a directory deep_logic 3 359 Feb-28-2019, 02:57 PM
Last Post: deep_logic
  Download multiple large json files at once halcynthis 0 251 Feb-14-2019, 08:41 AM
Last Post: halcynthis

Forum Jump:

Users browsing this thread: 1 Guest(s)