Python is a multi-purpose language and widely used for scripting. We can write Python scripts to automate day-to-day things. Let’s say we want to download google images with multiple search queries. Instead of doing it manually we can automate the process. How to install needed Module :
pip install google_images_download
Let’s see how to write a Python script to download the Google images in Python using google_images_download module. Below is the Python code :
Python3
from google_images_download import google_images_download
response = google_images_download.googleimagesdownload()
search_queries =
[
'The smartphone also features an in display fingerprint sensor.' ,
'The pop up selfie camera is placed aligning with the rear cameras.' ,
,
'The smartphone could be fuelled by a 3 700mAh battery.' ,
]
def downloadimages(query):
arguments = {"keywords": query,
" format ": "jpg",
"limit": 4 ,
"print_urls": True ,
"size": "medium",
"aspect_ratio":"panoramic"}
try :
response.download(arguments)
except FileNotFoundError:
arguments = {"keywords": query,
" format ": "jpg",
"limit": 4 ,
"print_urls": True ,
"size": "medium"}
try :
response.download(arguments)
except :
pass
for query in search_queries:
downloadimages(query)
print ()
|
Output:
Note: Some images could not be open because of the downloading error. A separate “downloads” folder will be created with all the images.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!