Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Load multiple images with incremental urls

i have 1 problem i would like everyone to help. I need to download image files on 1 website, links https://acb.xyz.0001.jpg and the following files it similarly only change the number of extensions to https://acb.xyz.0002.jpg. Is there a way to use python to save those images. I tried to manually save each photo but it was too much.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Assuming you have already know how many image you need to download you can use this code.

import requests
# Url to download content from 
URL = "http://thuvien.hmu.edu.vn/pages/cms/TempDir/books/01419632-d344-4a8e-9f53-4e40be647c3a/2022/09/13/202209071405-e0309899-377b-43d1-9033-972aa96844b5/FullPreview/"
# suffix 000001.jpg
# :05d
# Maximum number of image to download
max_image_size =3

# function for writing requests to png files
def dumpfile(n, m):
    f = open(n, 'wb')
    f.write(m)
    f.close()

# Itearate over the image urls and call dumpfile function
for i in range(1,max_image_size):
    suffix = str(f'{i:06d}')
    target=URL+ suffix+'.jpg'# added number of png
    print(target)
    response = requests.get(target)
    
    fileName=str(i)+'.jpg'
    dumpfile(fileName,response.content)



Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading