loop though jpgs one by one to download to computer

You can simply use the requests library to do this:

import requests

urls = ['https://keithgalli.github.io/web-scraping/images/italy/lake_como.jpg',
 'https://keithgalli.github.io/web-scraping/images/italy/pontevecchio.jpg',
 'https://keithgalli.github.io/web-scraping/images/italy/riomaggiore.jpg']

for img_num,url in enumerate(urls):
    r = requests.get(url)
    with open(f'D:\\Img_{img_num+1}.jpg','wb') as f:
        f.write(r.content)

Output Images:

Image 1:

enter image description here

Image 2:

enter image description here

Image 3:

enter image description here

You can also achieve the same result using urllib.request.urlretrieve:

import urllib.request as req

urls = ['https://keithgalli.github.io/web-scraping/images/italy/lake_como.jpg',
 'https://keithgalli.github.io/web-scraping/images/italy/pontevecchio.jpg',
 'https://keithgalli.github.io/web-scraping/images/italy/riomaggiore.jpg']

[req.urlretrieve(url,f'D:\\Img_{img_num+1}.jpg') for img_num,url in enumerate(urls)]

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top