-1

I have a handful of lists of dictionaries that look like this

list1 = [{a:b}, {c,d}, {e,f}]
list2 = [{aa:bb}, {cc,dd}, {ee,ff}]

The key is an id and the value is a URL. What I am attempting to do is loop though each list of dictionaries and grab the image at the URL(using request or urllib2) and write it to disk using the key as the file name plus some additional identifier. Maybe something like this.

5G4d3sweUI89_list1.jpg

I'm sure there is an easy solution for this but I'm just not thinking of it. I've jumped into the water before I learned how to swim.

MixedBeans
  • 159
  • 4
  • 17

1 Answers1

1

Here's the general flow you're going to want to implement:

import urllib.request

...

for dicts in list1:                  # iterate over the list of dicts
    for url, filename in dicts.items(): # for each dict, iterate over each key-value pair
        urllib.request.urlretrieve(url, filename)

Basically, just iterate over all of your key-value pairs and then do the thing for all of them. For other ways to download images using python, see this question.

Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53