Vexaloom Labs

Use Google Trends Interest & Related Query Scraper with Python

Get interest-over-time, interest-by-region, and related topics/queries for any keyword, location, time range and Google surface, with side-by-side comparison for up to five keywords.

1. Choose the data you need

Review the published README for supported collection modes, examples, and limits. The recipe below uses the current published input definition.

2. Prepare a source-based input

This JSON contains published prefills and required-field defaults. Review every value for your task before running it; it is not a promise of successful collection.

{
  "category": "0",
  "compareMode": false,
  "geo": "US",
  "geoResolution": "",
  "includeTrendingNews": false,
  "maxItems": 3,
  "mode": "interest",
  "searchTerms": [
    "tesla"
  ],
  "searchType": "",
  "timeRange": "today 12-m",
  "trendingCategory": "all",
  "trendingHours": "4"
}

Download input.example.json and save your reviewed copy as input.json.

FieldTypeRequiredDescription
modestringoptionalWhat to scrape. 'Interest over time & related queries' is the Google Trends Explore view (keywords required). 'Trending now' lists what is spiking in a country right now.
searchTermsarrayoptionalOne or more search terms to analyze (mode=interest). Each term becomes its own dataset row, or enable Comparison mode to compare up to 5 terms side by side. Example: `tesla` or `tesla, ford, toyota`.
compareModebooleanoptionalCompare all search terms on one shared 0-100 scale in a single row (Google Trends comparison view, maximum 5 terms). Off means each term is scraped independently.
startUrlsarrayoptionalPaste Google Trends links to scrape them directly: explore links (trends.google.com/trends/explore?q=..., including www.google.com/trends/... redirect links) and embedded-chart links (trends.google.com/trends/embed/explore/...?req=...). Trending Now links (trends.google.com/trending?geo=...) are supported too. URL settings override the fields above; they are merged with your search terms.
geostringoptionalCountry, state/region or metro area to analyze. Leave empty for worldwide. Trending Now uses the country part of this location.
timeRangestringoptionalTime window for the interest data (mode=interest). 'now' ranges return minute-level points; 'today' ranges return day/week points. Choose 'Custom range' to enter exact dates below.
customDateRangestringoptionalOnly used when 'Time range' = 'Custom range': 'YYYY-MM-DD YYYY-MM-DD' (e.g. '2024-01-01 2024-12-31') or 'YYYY-MM-DDTHH YYYY-MM-DDTHH' for hourly granularity.
categorystringoptionalGoogle Trends category filter (mode=interest). 0 = All categories.
searchTypestringoptionalWhich Google surface to query (mode=interest). Web Search is the default.
geoResolutionstringoptionalBreakdown level for 'interest by region' (mode=interest). Auto lets Google pick the right level for the location; other levels are applied when the location supports them.
trendingHoursstringoptionalHow far back the Trending Now list goes (mode=trending).
trendingCategorystringoptionalFilter the Trending Now list to one of Google's trending categories (mode=trending).
includeTrendingNewsbooleanoptionalAttach news headlines, links and sources from Google's Trending RSS feed to trending items whose titles it covers (about ten highlighted stories per country, anywhere in the list).
maxItemsintegeroptionalMaximum dataset records per run: each interest row counts as one record, each trending item as one record. Remaining work stops once the limit is reached.

3. Start an Actor run

Set APIFY_TOKEN in your environment. Python 3.10 or newer is sufficient; this recipe uses no third-party packages.

Execution may incur charges. Review current pricing on Apify. The request asks for a 120-second timeout and a charge limit; these settings are subject to Apify’s pricing and do not guarantee an all-inclusive spending cap.

import json
import os
import urllib.request

# Save the schema-derived example as input.json; review and edit it first.
with open("input.json", encoding="utf-8") as stream:
    actor_input = json.load(stream)

token = os.environ["APIFY_TOKEN"]
request = urllib.request.Request(
    "https://api.apify.com/v2/acts/NEZGbjPfvDGos0EFq/runs?timeout=120&maxTotalChargeUsd=0.50",
    data=json.dumps(actor_input).encode("utf-8"),
    headers={"Authorization": "Bearer " + token, "Content-Type": "application/json"},
    method="POST",
)
# This starts a potentially billable run. Do not automatically retry this POST.
with urllib.request.urlopen(request, timeout=40) as response:
    run = json.load(response)["data"]
print("Run ID:", run["id"])
print("Status:", run["status"])
# Inspect and download results in Apify Console once the run succeeds.

4. Inspect the actual results

Open the run in Apify Console and wait for a successful completion. Use the published output schema to locate results and the dataset schema to understand declared views. Missing or optional record fields must not be treated as guaranteed values.

Google Trends dataset rows: interest-over-time, interest-by-region and related-query records plus Trending Now records.

Questions before you run

Which inputs are required?

No top-level fields are marked required in the published schema. Conditional requirements can still apply; check the README.

What does this guide verify?

The fields, prefills, and schema links are rendered from the published build. This is a usage recipe, not a paid live extraction test. Source availability and collection results can vary.

What if the run request times out?

Check Apify Console before retrying. The first request may already have created a run. Do not automatically repeat a run-creation POST.

Generated from source build nDRCeMAwxTkbOpvlo and its README and schemas. Source changes regenerate this guide; no third-party editorial claims are inferred.