How to download Google Images using Python
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 :
# importing google_images_download module from google_images_download import google_images_download # creating object 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.', '''In terms of storage Vivo V15 Pro could offer up to 6GB of RAM and 128GB of onboard storage.''', 'The smartphone could be fuelled by a 3 700mAh battery.', ] def downloadimages(query): # keywords is the search query # format is the image file format # limit is the number of images to be downloaded # print urs is to print the image file url # size is the image size which can # be specified manually ("large, medium, icon") # aspect ratio denotes the height width ratio # of images to download. ("tall, square, wide, panoramic") arguments = {"keywords": query, "format": "jpg", "limit":4, "print_urls":True, "size": "medium", "aspect_ratio: panoramic"} try: response.download(arguments) # Handling File NotFound Error except FileNotFoundError: arguments = {"keywords": query, "format": "jpg", "limit":4, "print_urls":True, "size": "medium"} # Providing arguments for the searched query try: # Downloading the photos based # on the given arguments response.download(arguments) except: pass # Driver Code 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.
Recommended Posts:
- Download Anything to Google Drive using Google colab
- Simple Multithreaded Download Manager in Python
- Pytube | Python library to download youtube videos
- Python | Program to download complete Youtube playlist
- YouTube Media/Audio Download using Python | pafy
- Python | How to download windows lock-screen wallpapers
- Python | Download YouTube videos using youtube_dl module
- Reading images in Python
- Working with Images in Python
- Python | Grayscaling of Images using OpenCV
- Python | Working with PNG Images using Matplotlib
- Python | Uploading images in Django
- Python | Display images with PyGame
- Extract images from video in Python
- Python | Denoising of colored images using opencv
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



