2026 年 pytrends 替代方案:以 Python 取得 Google Trends 資料並應對 429 錯誤
A pytrends alternative in 2026: Google Trends data in Python without 429 errors
Serenido 示範以 Python 使用 Apify 託管工具取得 Google Trends 資料,作為 pytrends 的替代方案。工具會在請求遭封鎖時換用新工作階段及住宅 IP 重試,每 1,000 項結果收費 $1;重試後仍遭封鎖或搜尋量不足的關鍵詞會略過且不收費。
For years, pytrends was the default way to get Google Trends data in Python. Today its GitHub repository is archived (read-only), and its last release on PyPI was in April 2023. Its issue tracker has 28 issues with "429" in the title, the "too many requests" error Google sends when it blocks you.
Google announced an official Trends API in July 2025, but access is by application while it is in alpha.
This post shows another way: a hosted tool that fetches Trends data, retries blocked requests on a fresh IP, and returns clean JSON.
Disclosure: I built the tool used below. It runs on Apify and costs $1 per 1,000 results.
What you get for each keyword
- Interest over time (the 0 to 100 curve), plus a summary: average, latest week, peak week, change in % and a direction (rising, stable or falling)
- Rising and top related queries
- Interest by region
- Optional: today's Trending Now searches for any country, with traffic and news links
Search types: web, images, news, YouTube and Google Shopping. Time ranges: from the past hour to all time (2004).
Step 1: Install the client
pip install apify-client
You need a free Apify account for the API token. The free plan gives $5 of usage every month, no credit card needed. Find the token in Apify Console under Settings > API & Integrations.
Step 2: Get the trends
from apify_client import ApifyClient
client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("serenido/google-trends-reliable").call(run_input={
"searchTerms": ["gym wear", "vw golf"],
"geo": "US",
"timeRange": "past_12_months",
"includeRawData": True,
})
for row in client.dataset(run["defaultDatasetId"]).iterate_items():
if row["type"] != "keyword":
continue
change = row["trendChangePct"]
change_text = f" ({change:+}%)" if change is not None else ""
print(f'{row["keyword"]}: {row["trendDirection"]}{change_text}, peak week {row["peakDate"]}')
for q in row["relatedQueries"]["rising"][:3]:
print(" rising:", q["query"], q["value"])
full_weeks = [p["value"] for p in row["interestOverTime"] if not p["isPartial"]]
print(" last 4 full weeks:", full_weeks[-4:])
includeRawData adds the full arrays (interestOverTime, interestByRegion, relatedQueries). Without it you get one flat row per keyword, which is easier to open in Excel.
The result
From a real run on October 14:
gym wear: stable (+10%), peak week 2026-04-12
rising: thriving gym wear +350%
rising: gym wear men's +250%
rising: women's gym wear +200%
last 4 full weeks: [64, 68, 61, 58]
vw golf: stable (-12%), peak week 2026-04-12
rising: vw golf 2026 +2,250%
rising: 2026 vw golf r +900%
rising: vw golf plus +250%
last 4 full weeks: [47, 50, 50, 48]
The change in % compares the average of the last quarter of the period with the first quarter. +15% or more is "rising", -15% or less is "falling".
Three things to know about Trends data
1. The numbers are relative, not search counts. 100 is the highest point for that keyword in the chosen time and place. A keyword at 50 had half the searches of its own peak, not 50 searches.
2. Google samples the data. I ran the same request twice, about two hours apart. The first run said "gym wear" peaked in the week of February 8; the second said April 12. The average moved from 74.7 to 74.5. Look at the shape of the curve and the direction, not at one exact week or value.
3. The last week is often unfinished. It is marked isPartial, and it can look like a jump. The code above leaves it out.
Blocks and billing
Google blocks Trends scrapers a lot. The tool retries a blocked request with a fresh session and a fresh residential IP, so one block does not end the run. Keywords that are still blocked after all retries, or that have too little search volume for Google to show data, are skipped and not charged. The run's status message lists them.
Cost
$1 per 1,000 results (one result = one keyword, or one Trending Now search), plus a small start fee of $0.00005 per GB of memory, which is $0.0002 per run at the default 4 GB.
Use it from an AI assistant
The tool also works through Apify's MCP server, so Claude, ChatGPT, Cursor or VS Code can run it for you. Add this server URL to your app: https://mcp.apify.com?tools=serenido/google-trends-reliable
Links
- The tool: Google Trends Scraper on Apify
- Code examples (Python, JavaScript, curl): github.com/serenido/google-trends-scraper
If you used pytrends before and miss something, tell me in the comments.
來源:DEV Community · dev.to