Google Images API: How to Extract Image Search Results

Learn how to extract Google Images search results with a SERP API. Use Python to collect image titles, thumbnails, image URLs, source pages, domains, positions, and export the data to CSV.

talor ai
最後更新於
9 分鐘閱讀

Quick answer: You can extract Google Images results by sending an image search query to a SERP API, receiving structured image result data, normalizing fields such as title, thumbnail, image URL, source page, domain, and position, then exporting the results to CSV.

Google Images data can be useful when your workflow depends on visual search results, not only web pages.

For example, you may want to understand:

  • which product images appear for a search query

  • which domains are visible in image search

  • what thumbnails competitors use

  • which images appear for branded searches

  • how image results change by country or language

  • which visual assets may be useful for content research

What We Will Build

We will create a Python workflow:

Image search query
→ SERP API request
→ Extract image results
→ Normalize image fields
→ Export results to CSV

The final CSV can include:

Field

Meaning

query

Image search query

position

Result position

title

Image result title

image_url

Direct image URL, if available

thumbnail_url

Thumbnail image URL

source_page

Page where the image appears

source_domain

Domain of the source page

width / height

Image dimensions, if available

collected_at

Collection timestamp

This is useful for visual SEO, e-commerce research, brand monitoring, competitor analysis, content research, and AI dataset discovery workflows.

Why Use a SERP API for Image Search?

You can try to scrape Google Images manually, but image search pages are usually dynamic and harder to parse than standard web results.

Common issues include:

  • lazy-loaded images

  • thumbnail URLs vs original image URLs

  • changing page layouts

  • duplicate visual results

  • redirects from source pages

  • missing dimensions

  • location and language differences

  • blocked requests or CAPTCHA challenges

A SERP API gives you a cleaner workflow. You send a query and receive structured data that your script can parse consistently.

Step 1: Set Environment Variables

Do not hardcode your API key.

export TALORDATA_API_KEY="your_api_key_here"
export TALORDATA_SERP_ENDPOINT="your_talordata_serp_endpoint_here"

On Windows PowerShell:

$env:TALORDATA_API_KEY="your_api_key_here"
$env:TALORDATA_SERP_ENDPOINT="your_talordata_serp_endpoint_here"

Install the Python package:

pip install requests

Use the endpoint and authentication method shown in your dashboard or API documentation.

Step 2: Create a Request Helper

Keep the request layer separate from the parsing logic. That way, if your endpoint or authentication method changes, you only update one function.

import os
import requests


def require_env(name):
    value = os.getenv(name)
    if not value:
        raise RuntimeError(f"Missing required environment variable: {name}")
    return value


TALORDATA_API_KEY = require_env("TALORDATA_API_KEY")
TALORDATA_SERP_ENDPOINT = require_env("TALORDATA_SERP_ENDPOINT")


def call_serp_api(payload):
    headers = {
        "Authorization": f"Bearer {TALORDATA_API_KEY}",
        "Content-Type": "application/json",
    }

    response = requests.post(
        TALORDATA_SERP_ENDPOINT,
        json=payload,
        headers=headers,
        timeout=30,
    )

    response.raise_for_status()
    return response.json()

Some API setups use GET instead of POST, or pass the API key as a query parameter. Keep those details inside this helper.

Step 3: Send a Google Images Request

Create a function for Google Images search.

def search_google_images(query, location="United States", language="en", country="us", device="desktop"):
    payload = {
        "engine": "google_images",
        "q": query,
        "location": location,
        "hl": language,
        "gl": country,
        "device": device,
        "num": 20,
        "output": "json",
    }

    return call_serp_api(payload)

Depending on your API setup, the image search type may use another value, such as google_images, images, or tbm=isch. Keep this function isolated so you can adjust the request format without changing the rest of the script.

Step 4: Extract Image Results

Image result data may appear under different keys, such as:

images_results
image_results
images

The parser below handles several common response shapes.

from datetime import datetime, timezone
from urllib.parse import urlparse


def clean_text(value):
    if not value:
        return ""
    return " ".join(str(value).split())


def get_domain(url):
    if not url:
        return ""

    parsed = urlparse(url)
    return parsed.netloc.replace("www.", "")


def get_image_results(serp_json):
    return (
        serp_json.get("images_results")
        or serp_json.get("image_results")
        or serp_json.get("images")
        or []
    )


def normalize_image_results(serp_json, query):
    results = get_image_results(serp_json)
    collected_at = datetime.now(timezone.utc).isoformat()

    rows = []

    for index, item in enumerate(results, start=1):
        image_url = (
            item.get("original")
            or item.get("image")
            or item.get("image_url")
            or item.get("link")
            or ""
        )

        thumbnail_url = (
            item.get("thumbnail")
            or item.get("thumbnail_url")
            or item.get("thumbnail_link")
            or ""
        )

        source_page = (
            item.get("source")
            or item.get("source_page")
            or item.get("page_url")
            or item.get("link")
            or ""
        )

        rows.append({
            "query": query,
            "position": item.get("position") or item.get("rank") or index,
            "title": clean_text(item.get("title")),
            "image_url": image_url,
            "thumbnail_url": thumbnail_url,
            "source_page": source_page,
            "source_domain": get_domain(source_page),
            "width": item.get("width") or item.get("image_width") or "",
            "height": item.get("height") or item.get("image_height") or "",
            "collected_at": collected_at,
        })

    return rows

This gives you a clean structure that works well for spreadsheets, dashboards, and databases.

Step 5: Export Image Results to CSV

import csv


CSV_COLUMNS = [
    "query",
    "position",
    "title",
    "image_url",
    "thumbnail_url",
    "source_page",
    "source_domain",
    "width",
    "height",
    "collected_at",
]


def export_to_csv(rows, filename="google_images_results.csv"):
    if not rows:
        print("No image results found.")
        return

    with open(filename, mode="w", newline="", encoding="utf-8") as file:
        writer = csv.DictWriter(file, fieldnames=CSV_COLUMNS)
        writer.writeheader()
        writer.writerows(rows)

    print(f"Exported {len(rows)} image results to {filename}")

Complete Python Example

import os
import csv
import requests

from datetime import datetime, timezone
from urllib.parse import urlparse


CSV_COLUMNS = [
    "query",
    "position",
    "title",
    "image_url",
    "thumbnail_url",
    "source_page",
    "source_domain",
    "width",
    "height",
    "collected_at",
]


def require_env(name):
    value = os.getenv(name)
    if not value:
        raise RuntimeError(f"Missing required environment variable: {name}")
    return value


TALORDATA_API_KEY = require_env("TALORDATA_API_KEY")
TALORDATA_SERP_ENDPOINT = require_env("TALORDATA_SERP_ENDPOINT")


def call_serp_api(payload):
    headers = {
        "Authorization": f"Bearer {TALORDATA_API_KEY}",
        "Content-Type": "application/json",
    }

    response = requests.post(
        TALORDATA_SERP_ENDPOINT,
        json=payload,
        headers=headers,
        timeout=30,
    )

    response.raise_for_status()
    return response.json()


def search_google_images(query, location="United States", language="en", country="us", device="desktop"):
    payload = {
        "engine": "google_images",
        "q": query,
        "location": location,
        "hl": language,
        "gl": country,
        "device": device,
        "num": 20,
        "output": "json",
    }

    return call_serp_api(payload)


def clean_text(value):
    if not value:
        return ""
    return " ".join(str(value).split())


def get_domain(url):
    if not url:
        return ""

    parsed = urlparse(url)
    return parsed.netloc.replace("www.", "")


def get_image_results(serp_json):
    return (
        serp_json.get("images_results")
        or serp_json.get("image_results")
        or serp_json.get("images")
        or []
    )


def normalize_image_results(serp_json, query):
    results = get_image_results(serp_json)
    collected_at = datetime.now(timezone.utc).isoformat()

    rows = []

    for index, item in enumerate(results, start=1):
        image_url = (
            item.get("original")
            or item.get("image")
            or item.get("image_url")
            or item.get("link")
            or ""
        )

        thumbnail_url = (
            item.get("thumbnail")
            or item.get("thumbnail_url")
            or item.get("thumbnail_link")
            or ""
        )

        source_page = (
            item.get("source")
            or item.get("source_page")
            or item.get("page_url")
            or item.get("link")
            or ""
        )

        rows.append({
            "query": query,
            "position": item.get("position") or item.get("rank") or index,
            "title": clean_text(item.get("title")),
            "image_url": image_url,
            "thumbnail_url": thumbnail_url,
            "source_page": source_page,
            "source_domain": get_domain(source_page),
            "width": item.get("width") or item.get("image_width") or "",
            "height": item.get("height") or item.get("image_height") or "",
            "collected_at": collected_at,
        })

    return rows


def export_to_csv(rows, filename="google_images_results.csv"):
    if not rows:
        print("No image results found.")
        return

    with open(filename, mode="w", newline="", encoding="utf-8") as file:
        writer = csv.DictWriter(file, fieldnames=CSV_COLUMNS)
        writer.writeheader()
        writer.writerows(rows)

    print(f"Exported {len(rows)} image results to {filename}")


if __name__ == "__main__":
    query = "modern office desk setup"

    serp_json = search_google_images(
        query=query,
        location="United States",
        language="en",
        country="us",
        device="desktop",
    )

    rows = normalize_image_results(serp_json, query)
    export_to_csv(rows)

After running the script, you should get:

google_images_results.csv

Example Output

query,position,title,image_url,thumbnail_url,source_page,source_domain,width,height,collected_at
modern office desk setup,1,Example Desk Setup,https://example.com/image.jpg,https://example.com/thumb.jpg,https://example.com/blog/desk-setup,example.com,1200,800,2026-06-22T00:00:00Z
modern office desk setup,2,Minimal Office Setup,https://example.org/photo.jpg,https://example.org/thumb.jpg,https://example.org/office-ideas,example.org,1600,900,2026-06-22T00:00:00Z

Useful Parameters to Adjust

Parameter

Why it matters

q

Image search query

location

Target location

gl

Country or market

hl

Search language

device

Desktop or mobile result behavior

num

Number of image results

ijn / pagination

More image result pages, if supported

For production workflows, store location, country, language, device, and timestamp with every result. Image search results can change over time and may differ across markets.

Common Use Cases

Visual SEO research

Track which images and source pages appear for important queries.

Brand monitoring

Check what appears in image search for brand names, product names, executives, campaigns, or events.

E-commerce image research

Analyze product image styles, source domains, thumbnails, and competitor visibility.

Content research

Use image results to understand how a topic is visually represented across the web.

AI and RAG workflows

Use image search results as a discovery layer. Your system can collect image URLs and source pages, then decide which sources need deeper review.

Test the Google Images API for free>>

FAQ

What is a Google Images API?

A Google Images API is a way to collect Google Images-style search results programmatically. In this tutorial, it means using a SERP API to return structured image search data.

Can I extract Google Images results with Python?

Yes. You can use Python to send image search queries to a SERP API, parse the structured response, and export image result fields to CSV.

What fields can I collect from image search results?

Common fields include title, image URL, thumbnail URL, source page, source domain, position, width, height, and collection timestamp.

Can I download the images from the results?

Technically, you can fetch image URLs if they are available, but you should check copyright, licensing, and usage permissions before downloading or reusing any image.

Is CSV enough for image search tracking?

CSV is fine for testing and small reports. For recurring tracking, deduplication, dashboards, and historical comparison, use a database.

立即開展您的數據業務

加入全球最強大的代理網絡

免費試用