From 434c67d743d2017e96d4bdc4c65a70ec88c2622c Mon Sep 17 00:00:00 2001 From: sameer Date: Sat, 1 Oct 2022 12:32:04 +0530 Subject: [PATCH] Added Image Scraper --- scripts/Image Scraper/README.md | 12 ++++++++++++ scripts/Image Scraper/script.py | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 scripts/Image Scraper/README.md create mode 100644 scripts/Image Scraper/script.py diff --git a/scripts/Image Scraper/README.md b/scripts/Image Scraper/README.md new file mode 100644 index 0000000..6f14742 --- /dev/null +++ b/scripts/Image Scraper/README.md @@ -0,0 +1,12 @@ +# Image Scraper +### Download images with a given url + +This is a simple script that lets you download images from a list of urls + + +#### Usage + +* Clone the repo +* change the urls in script.py +* run python script.py + diff --git a/scripts/Image Scraper/script.py b/scripts/Image Scraper/script.py new file mode 100644 index 0000000..6321265 --- /dev/null +++ b/scripts/Image Scraper/script.py @@ -0,0 +1,26 @@ +from email.mime import image +import urllib.request +import os + +#You can replace the replace the urls links according to your needs +urls = [ + 'https://images.unsplash.com/photo-1664552399245-8ee5fa8eddd2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=685&q=80', + + 'https://images.unsplash.com/photo-1664519803504-a8ed329d9381?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=735&q=80', + + 'https://images.unsplash.com/photo-1664361859625-07f20702b6c2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1074&q=80' + +] + +# This function will create a images folder to save our images +def downloadImage(image_urls): + crtFileLocation = os.getcwd() + os.makedirs('Images') + + for x in range(0, len(image_urls)): + filename = 'image_' + str(x) + '.png' + print(f'downloading {x+1} out of {len(image_urls)} images') + urllib.request.urlretrieve(image_urls[x], os.path.join(crtFileLocation, 'Images', filename)) + +downloadImage(urls) +