Skip to content

Scrape Google Trends data using Python or the Bright Data API. Get real-time search trends, filter by location, category, and time range, and scale effortlessly.

Notifications You must be signed in to change notification settings

luminati-io/google-trends-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Trends Scraper API

Promo

This repository provides two approaches for collecting Google Trends data:

  1. Free Scraper: A lightweight solution for small-scale projects, testing, personal research, and educational purposes.
  2. Bright Data Google Trends Scraper API: A robust, high-volume solution for enterprise-level, scalable, and reliable data extraction.

Table of Contents

Free Scraper

bright-data-google-trends-api-screenshot-google-trends-page

A simple Google Trends scraper for small-scale data collection projects.

Setup

Requirements:

  • Python 3.9+
  • Playwright (for browser automation)

Installation:

pip install playwright
playwright install

New to web scraping? Follow our beginner's guide to web scraping with Python

Quick Start

  1. Edit these variables in google-trends-scraper.py:
query = "cryptocurrency"  # Your search term
geo = "US"                # Country code
hl = "en-US"              # Language code
  1. Run the script

đź’ˇ Pro Tip: Set HEADLESS = False to reduce detection by Google's anti-scraping systems.

Sample Output

{
    "geoCode": "US-DC",
    "geoName": "District of Columbia",
    "value": [100],
    "formattedValue": ["100"],
    "maxValueIndex": 0,
    "hasData": [true],
}

👉 See the full JSON output.

Limitations

Free Scraper comes with limitations:

  • High risk of IP blocks
  • Limited request volume
  • Frequent CAPTCHAs
  • Unreliable for large-scale scraping

For reliable, large-scale scraping, you'll need a more advanced solution.

Bright Data Enterprise Solution

Bright Data's Google Trends API provides structured Google Trends data with customizable search parameters. Built on the same advanced technology as the SERP API, it provides:

  • Global Location Accuracy: Tailor results to any location
  • Pay-Per-Success Model: Only pay for successful requests
  • Real-Time Data: Retrieve up-to-date search results in seconds
  • Scalability: Handle unlimited requests with no volume restrictions
  • Cost Efficiency: Save on infrastructure and maintenance costs
  • Highest Reliability: Consistent performance with built-in anti-blocking measures
  • Technical Support: Expert assistance available when needed

Getting Started

  1. Prerequisites:
  2. Setup: Follow our step-by-step guide to integrate the API
  3. Implementation Methods:
    • Direct API Access
    • Native Proxy-Based Access

Direct API Access

Make a direct request to the API endpoint:

cURL Example:

curl https://api.brightdata.com/request \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer API_TOKEN" \
  -d '{
        "zone": "ZONE_NAME",
        "url": "https://trends.google.com/trends/explore?q=coffee&geo=GB&brd_trends=timeseries,geo_map&brd_json=1",
        "format": "raw"
      }'

Python Example:

import requests
import json

url = "https://api.brightdata.com/request"
headers = {"Content-Type": "application/json", "Authorization": "Bearer API_TOKEN"}

payload = {
    "zone": "ZONE_NAME",
    "url": "https://trends.google.com/trends/explore?q=coffee&geo=GB&brd_trends=timeseries,geo_map&brd_json=1",
    "format": "raw",
}

response = requests.post(url, headers=headers, json=payload)

with open("serp_direct_api.json", "w") as file:
    json.dump(response.json(), file, indent=4)

print("Response saved to 'serp_direct_api.json'.")

👉 See the full JSON output.

Note: Use brd_json=1 for parsed JSON. Additional parameters such as geo and brd_trends are explained in the Advanced Features section below.

Native Proxy-Based Access

You can also use our proxy routing method:

cURL Example:

curl -i \
  --proxy brd.superproxy.io:33335 \
  --proxy-user "brd-customer-<customer-id>-zone-<zone-name>:<zone-password>" \
  -k \
  "https://trends.google.com/trends/explore?q=coffee&geo=GB&brd_trends=timeseries,geo_map&brd_json=1"

Python Example:

import requests
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

host = "brd.superproxy.io"
port = 33335
username = "brd-customer-<customer-id>-zone-<zone-name>"
password = "<zone-password>"
proxy_url = f"http://{username}:{password}@{host}:{port}"

proxies = {"http": proxy_url, "https": proxy_url}
url = "https://trends.google.com/trends/explore?q=coffee&geo=GB&brd_trends=timeseries,geo_map&brd_json=1"
response = requests.get(url, proxies=proxies, verify=False)

with open("serp_native_proxy.json", "w", encoding="utf-8") as file:
    file.write(response.text)

print("Response saved to 'serp_native_proxy.json'.")

👉 See the full JSON output.

Note: For production environments, load Bright Data's SSL certificate as described in our SSL Certificate Guide.

Advanced Features

Widgets

bright-data-google-trends-api-screenshot-timeseries-and-geomap

Google Trends provides different widgets to extract meaningful insights. You can specify which widgets you want using the brd_trends parameter:

Available Widgets:

  • timeseries → Interest over time
  • geo_map → Interest by subregion

Using Multiple Widgets:

You can combine multiple widgets by separating them with a comma:

curl --proxy brd.superproxy.io:33335 \
  --proxy-user brd-customer-<customer-id>-zone-<zone-name>:<zone-password> \
  -k "https://trends.google.com/trends/explore?q=ChatGPT&geo=US&brd_trends=timeseries,geo_map&brd_json=1"

Geographic Filtering

The geo parameter allows you to filter search trend data for a specific country (e.g., geo=US for the United States). If omitted, the API defaults to global trends.

Example:

curl --proxy brd.superproxy.io:33335 \
  --proxy-user brd-customer-<customer-id>-zone-<zone-name>:<zone-password> \
  -k "https://trends.google.com/trends/explore?q=coffee&geo=GB&brd_trends=timeseries,geo_map&brd_json=1"

Localization

bright-data-google-trends-api-screenshot-set-language

The hl parameter allows you to retrieve search trend data in a specific language:

  • It accepts a language code (e.g., en-US, fr-FR)
  • This affects the language of the returned data, not the actual search results

Example:

curl --proxy brd.superproxy.io:33335 \
  --proxy-user brd-customer-<customer-id>-zone-<zone-name>:<zone-password> \
  -k "https://trends.google.com/trends/explore?q=coffee&hl=fr-FR&brd_trends=timeseries,geo_map&brd_json=1"

Time Range

The date parameter defines a specific time range for retrieving trend data:

Value Time Range
now 1-H Past 1 hour
now 4-H Past 4 hours
now 1-d Past day (24 hours)
now 7-d Past 7 days
today 1-m Past 30 days
today 3-m Past 90 days
today 12-m Past 12 months (Default)
today 5-y Past 5 years
YYYY-MM-DD YYYY-MM-DD Custom date range

Example for Past 30 Days:

curl --proxy brd.superproxy.io:33335 \
  --proxy-user brd-customer-<customer-id>-zone-<zone-name>:<zone-password> \
  -k "https://trends.google.com/trends/explore?q=coffee&date=today+1-m&brd_trends=timeseries,geo_map&brd_json=1"

Example for Custom Date Range:

curl --proxy brd.superproxy.io:33335 \
  --proxy-user brd-customer-<customer-id>-zone-<zone-name>:<zone-password> \
  -k "https://trends.google.com/trends/explore?q=coffee&date=2025-01-02+2025-03-03&brd_trends=timeseries,geo_map&brd_json=1"

Category Filtering

The cat parameter allows you to narrow down search trends within a specific category:

  • By default, Google Trends searches across all categories
  • Categories are represented by numeric IDs
  • You can find the full list of category IDs on Google Trends

Example – Fetch trends for “Bitcoin” in the Business & Industrial category (cat=12):

curl --proxy brd.superproxy.io:33335 \
  --proxy-user brd-customer-<customer-id>-zone-<zone-name>:<zone-password> \
  -k "https://trends.google.com/trends/explore?q=bitcoin&cat=12&brd_trends=timeseries,geo_map&brd_json=1"

Search Type

The gprop (Google Property) parameter filters search trends by specific Google services:

Value Google Property
images Google Images
news Google News
froogle Google Shopping
youtube YouTube Search

If omitted, it defaults to a web search.

Examples:

  1. Image Search Trends (gprop=images):
curl --proxy brd.superproxy.io:33335 \
  --proxy-user brd-customer-<customer-id>-zone-<zone-name>:<zone-password> \
  -k "https://trends.google.com/trends/explore?q=nft+art&gprop=images&brd_trends=timeseries,geo_map&brd_json=1"
  1. News Search Trends (gprop=news):
curl --proxy brd.superproxy.io:33335 \
  --proxy-user brd-customer-<customer-id>-zone-<zone-name>:<zone-password> \
  -k "https://trends.google.com/trends/explore?q=AI+advancements&gprop=news&brd_trends=timeseries,geo_map&brd_json=1"
  1. YouTube Search Trends (gprop=youtube):
curl --proxy brd.superproxy.io:33335 \
  --proxy-user brd-customer-<customer-id>-zone-<zone-name>:<zone-password> \
  -k "https://trends.google.com/trends/explore?q=python+tutorials&gprop=youtube&brd_trends=timeseries,geo_map&brd_json=1"

Support & Resources

About

Scrape Google Trends data using Python or the Bright Data API. Get real-time search trends, filter by location, category, and time range, and scale effortlessly.

Topics

Resources

Stars

Watchers

Forks

Languages