How to Scrape Google Images Results
In my previous blog post, we can scrape thousands of Bing Images via SerpApi Bing Images APIs.
Google is one of the most popular search engines. And Google also offers Images Results based on keyword search.
Google Images search allows you to filter images results by size, color, type, time, and usage rights. You can also scrape related searches keywords in case you want to feed huge data to your AI product.
Google Images is always an invaluable resource for your product. But scraping Google data is always tricky and challenging. By using our SerpApi, you don't need to worry about that. We support all available parameters like location, country, language, filters, and more.
Setting up a SerpApi account
SerpApi offers a free plan for newly created accounts. Head to the sign-up page to register an account and complete your first search with our interactive playground. When you want to do more searches with us, please visit the pricing page.
Once you are familiar with all results, you can utilize SERP APIs using your API Key.
Scrape your first Google Images results with SerpApi
Head to the Google Images Results from the documentation on SerpApi for details.
In this tutorial, we will scrape top images when searching with "Eiffel tower" keyword. The data contains: "position", "title", "link", "source", "width", "height", and more. You can also scrape more information with SerpApi.
First, you need to install the SerpApi client library.
pip install google-search-results
Set up the SerpApi credentials and search.
import serpapi
import os, json, csv
params = {
'api_key': 'YOUR_API_KEY', # your serpapi api
'engine': 'google_images', # SerpApi search engine
'q': 'eiffel tower'
}
To retrieve Google Images Results for a given search query, you can use the following code:
client = serpapi.Client()
results = client.search(params)['images_results']
You can store Google Images Results JSON data in databases or export them to a CSV file.
import csv
header = ['position', 'title', 'link', 'source', 'width', 'height']
with open('google_images.csv', 'w', encoding='UTF8', newline='') as f:
writer = csv.writer(f)
writer.writerow(header)
for item in results:
print(item)
writer.writerow([item.get('position'), item.get('title'), item.get('link'), item.get('source'), item.get('original_width'), item.get('original_height')])
This example is using Python, but you can also use your all your favorite programming languages likes Ruby, NodeJS, Java, PHP, and more.
Want to scrape more images with Google Images? Check out this blog post.
If you have any questions, please feel free to contact me.