Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to download Google Images using Python
Google Images can be downloaded programmatically using Python packages that search and fetch images based on keywords. The google_images_download package provides a simple interface to download images by specifying search terms and parameters.
Installation
First, install the required package using pip ?
pip install google_images_download
Basic Image Download
Here's how to download a limited number of images with URL printing enabled ?
from google_images_download import google_images_download
# Instantiate the class
response = google_images_download.googleimagesdownload()
# Set download parameters
arguments = {
"keywords": "lilly,hills",
"limit": 5,
"print_urls": True
}
# Download images
paths = response.download(arguments)
# Print complete paths to the downloaded images
print(paths)
The output shows the download progress and final file paths ?
Image URL: https://assets.traveltriangle.com/blog/wp-content/uploads/2017/11/Hill-Stations-Near-Kolkata-cover1-400x267.jpg
Completed Image ====> 4.Hill-Stations-Near-Kolkata-cover1-400x267.jpg
Image URL: https://image.shutterstock.com/image-photo/distant-hills-hilly-steppe-curvy-260nw-1037414248.jpg
Completed Image ====> 5.distant-hills-hilly-steppe-curvy-260nw-1037414248.jpg
({'lilly': ['C:\python3\downloads\lilly\1.Lilly-Tougas.jpg',
'C:\python3\downloads\lilly\2.1200px-Eli_Lilly_and_Company.svg.png',
'C:\python3\downloads\lilly\3.nikki-lilly-this-morning.jpg',
'C:\python3\downloads\lilly\4.lily-plants.jpg',
'C:\python3\downloads\lilly\5.dish-lilly-ghalichi.jpg'],
'hills': ['C:\python3\downloads\hills\1.220px-Clouds_over_hills.jpg',
'C:\python3\downloads\hills\2.Bacin_zari_2015.jpg',
'C:\python3\downloads\hills\3.65ad9ac0-0455-4086-a4f4-1245f697d10e.png',
'C:\python3\downloads\hills\4.Hill-Stations-Near-Kolkata-cover1-400x267.jpg',
'C:\python3\downloads\hills\5.distant-hills-hilly-steppe-curvy-260nw-1037414248.jpg']}, 1)
Advanced Parameters
You can customize the download behavior with additional parameters ?
from google_images_download import google_images_download
response = google_images_download.googleimagesdownload()
arguments = {
"keywords": "sunset,mountains",
"limit": 10,
"print_urls": True,
"size": "medium",
"format": "jpg",
"output_directory": "my_images",
"image_directory": "nature_photos"
}
paths = response.download(arguments)
Key Parameters
| Parameter | Description | Example Value |
|---|---|---|
keywords |
Search terms separated by commas | "sunset,mountains" |
limit |
Maximum images per keyword | 10 |
size |
Image size filter | "medium", "large" |
format |
Image format filter | "jpg", "png" |
output_directory |
Main download folder | "my_images" |
Conclusion
The google_images_download package provides an easy way to download Google Images programmatically. Use parameters like limit, size, and format to customize your downloads and organize images into specific directories.
