跳到正文
DEV Community· mirtung·· 1 小時前AI 評分50

如何在 Node.js 解碼 Google News RSS 網址並避免 HTTP 429(2026 指南)

How to Decode Google News RSS URLs in Node.js Without Hitting HTTP 429 (2026 Guide)

AI 導讀

作者展示如何在 Node.js 透過兩步 batchexecute 流程解碼 Google News RSS 的 AU_yqL 文章連結,取回出版商網址,毋須使用 headless browser。

正文

If you've built a news monitor, AI research agent, or n8n workflow on top of Google News RSS (https://news.google.com/rss/search?q=...), you've probably hit the same annoying wall:

https://news.google.com/rss/articles/CBMiqgFBVV95cUxQNDlWaVNLMGhDTHpmeHc...

Google News RSS no longer gives you the real publisher URL (reuters.com, techcrunch.com, npr.org), and it never includes the article body text. Worse, the old Base64 decoding trick stopped working once Google switched to opaque AU_yqL tokens.

In this guide, I'll show you:

  1. How the modern 2-step batchexecute decoder works in plain Node.js (zero headless browser required)
  2. Why naive loops immediately hit HTTP 429 rate limits around 15–30 articles
  3. How to run it reliably in n8n or AI agents without maintaining proxies yourself

Why Old Base64 Decoders Broke

Before mid-2024, the CBMi... token in Google News RSS URLs was simply a Base64-encoded protobuf containing the plaintext publisher URL.

Today, most fresh articles use an opaque AU_yqL token that has to be exchanged with Google's internal RPC endpoint (batchexecute) using a per-article signature (data-n-a-sg) and timestamp (data-n-a-ts).


Step-by-Step: Decoding Google News URLs in Node.js

Here is the minimal two-step approach using Node 22's built-in fetch (no Puppeteer or Playwright needed):

const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/131.0.0.0 Safari/537.36';

export async function decodeGoogleNewsUrl(articleId) {
  // Step 1: Fetch lightweight /rss/articles/ page for signature & timestamp
  const pageRes = await fetch(`https://news.google.com/rss/articles/${articleId}`, {
    headers: { 'User-Agent': UA }
  });
  if (!pageRes.ok) throw new Error(`Step 1 HTTP ${pageRes.status}`);

  const html = await pageRes.text();
  const sg = html.match(/data-n-a-sg="([^"]+)"/)?.[1];
  const ts = html.match(/data-n-a-ts="([^"]+)"/)?.[1];
  if (!sg || !ts) return null;

  // Step 2: Exchange (articleId, ts, sg) via batchexecute RPC
  const inner = JSON.stringify([
    'garturlreq',
    [['X','X',['X','X'],null,null,1,1,'US:en',null,1,null,null,null,null,null,0,1],'X','X',1,[1,1,1],1,1,null,0,0,null,0],
    articleId,
    Number(ts),
    sg
  ]);

  const fReq = JSON.stringify([[['Fbv4je', inner, null, 'generic']]]);
  const rpcRes = await fetch('https://news.google.com/_/DotsSplashUi/data/batchexecute', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
      'User-Agent': UA
    },
    body: `f.req=${encodeURIComponent(fReq)}`
  });

  const text = await rpcRes.text();
  const match = text.match(/garturlres\\",\\"(https?:\/\/[^\\"]+)/);
  return match ? match[1].replace(/\\u003d/g, '=').replace(/\\u0026/g, '&') : null;
}

For 3–5 articles, this resolves clean URLs like https://www.npr.org/... in under a second.


The Production Trap: HTTP 429 at Scale

When I stress-tested this exact script on 30 consecutive articles from a single IP, Step 1 immediately started returning HTTP 429 (Too Many Requests) (0/30 decoded after the initial burst).

To make Google News decoding reliable in production, you need 4 things:

  1. Deduplicate RSS items first (across queries and across runs) so you never waste decode calls.
  2. Rotate IPs per request / on 429 retry using a proxy pool.
  3. Graceful paywall detection when extracting article text (so hard paywalls like Bloomberg/WSJ don't crash your pipeline).
  4. Clean boilerplate stripping (removing cookie banners, newsletter popups, and nav menus before feeding text to an LLM).

Zero-Maintenance Option (REST API / n8n / MCP)

If you don't want to manage proxy rotation, 429 retries, and HTML article parsing yourself, I packaged this exact pipeline into a lightweight Apify Actor:

👉 Google News Scraper & Article Extractor (URL Decoder)

  • 15 regional editions (US:en, GB:en, KR:ko, JP:ja, DE:de, etc.) + Topic feeds + site: / date filters
  • Built-in proxy rotation — tested at 30/30 (100%) URL decode rate in ~21 seconds
  • Optional full article text, author, and og:image extraction (paywalled articles are automatically detected and never billed for extraction)
  • Pay-per-event pricing: $0.80 / 1,000 RSS articles (+$0.40/1k decoded URLs, +$0.50/1k extracted texts) — works directly with n8n HTTP Request, Make, and MCP AI agents.

Quick cURL / n8n HTTP Request Example

curl -X POST "https://api.apify.com/v2/acts/mirtung~google-news-scraper-pro/run-sync-get-dataset-items" \
  -H "Authorization: Bearer YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "queries": ["AI agents", "OpenAI"],
    "countryLanguage": "US:en",
    "timeRange": "24h",
    "maxItems": 10,
    "decodeUrls": true,
    "extractArticleContent": true
  }'

Hope this saves you a few hours of debugging HTTP 429 errors! Feel free to drop a comment if you run into any edge cases with regional Google News feeds.

來源:DEV Community · dev.to