-2

What I have is the following data CSV data (2 columns)

  • ImageURL1, Name A
  • ImageURL1, Name B
  • ImageURL2, Name C

I want to download the image found at ImageURL1, and have two images file as Name A and Name B

Is there a way to do this?

Ideally, I would like to download each image + rename the file and then repeat the sequence again.

Or have all the unique image assets and duplicate those files later into the new image names

Perhaps with Python / Soup / bulk image downloader, etc

Vincent Tang
  • 3,758
  • 6
  • 45
  • 63

2 Answers2

2

You can import urllib3 module and use the following

urllib.urlretrieve(img_url, "path/name_of_img.jpg")

The first argument is the URL of the soon to be downloaded image and the second is the path to the folder/directory that you want it to be saved, plus the name and the extension of the image file.

I hope this works for you.

Ap_Ps
  • 21
  • 4
1

Have you tried any code? Please share if you have. From what you describe, there are three main goals: 1) open and read the CSV file, 2) download the image 3) rename the file. I'll give you general direction for each part, but it's up to you to complete the full code:

1) Open CSV and read data: Python has a specific library for CSV: CSV File Read and Write

Here is an example using csv.DictReader. You will have to modify for your specific CSV file format:

import csv
with open('filename.csv', 'rb') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        image_url = row['ImageURL']  # replace with your column heading
        filename = row['Name']  # replace with your column heading

2) Download image from web: You can use urllib.urlretrieve to download the image. Example:

import urllib
urllib.urlretrieve(image_url, filename)

3) Rename file. The above code will retrieve the url and save as filename, so maybe you do not need to do this step. If you still do, then os.rename(src, dst) will do the trick.

Hope this helps. Best of luck to you. Use plenty of print statements to debug your code. The Python documentation is your friend.

TBirkulosis
  • 581
  • 5
  • 8