<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: swiftscrape</title>
    <description>The latest articles on DEV Community by swiftscrape (@swiftscrape).</description>
    <link>https://dev.to/swiftscrape</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4040478%2F642a6e88-68a8-4fab-a3fc-5de7fd2e8301.png</url>
      <title>DEV Community: swiftscrape</title>
      <link>https://dev.to/swiftscrape</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/swiftscrape"/>
    <language>en</language>
    <item>
      <title>Google Trends ties its data tokens to your IP and it broke my scraper in a way I didn't expect</title>
      <dc:creator>swiftscrape</dc:creator>
      <pubDate>Tue, 21 Jul 2026 16:56:46 +0000</pubDate>
      <link>https://dev.to/swiftscrape/google-trends-ties-its-data-tokens-to-your-ip-and-it-broke-my-scraper-in-a-way-i-didnt-expect-dgp</link>
      <guid>https://dev.to/swiftscrape/google-trends-ties-its-data-tokens-to-your-ip-and-it-broke-my-scraper-in-a-way-i-didnt-expect-dgp</guid>
      <description>&lt;p&gt;I just shipped a Google Trends scraper as an Apify Actor (&lt;a href="https://apify.com/swiftscrape/google-trends-fast-scraper" rel="noopener noreferrer"&gt;https://apify.com/swiftscrape/google-trends-fast-scraper&lt;/a&gt;), and the most interesting part wasn't building it — it was a blocking bug that only showed up &lt;strong&gt;in production&lt;/strong&gt;, on the platform, that I couldn't reproduce locally no matter what I tried.&lt;/p&gt;

&lt;p&gt;If you've ever tried to scrape Google Trends and had it work on your laptop but mysteriously fail behind proxies, this one's for you. The root cause is non-obvious and I couldn't find it documented anywhere, so here's the whole thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why build another Google Trends scraper?
&lt;/h2&gt;

&lt;p&gt;Google Trends has no official API. There are scrapers out there, but the most-used one on the market is &lt;strong&gt;slow&lt;/strong&gt; (runs take minutes), it &lt;strong&gt;charges you even when it returns nothing&lt;/strong&gt;, and its multi-term comparison breaks when called from AI agents. Its reviews are full of "ran for 20 minutes, returned nothing, cost me money."&lt;/p&gt;

&lt;p&gt;That's a wedge. Same data, but: fast, and &lt;strong&gt;you only pay for terms that actually return data&lt;/strong&gt; — failed, blocked or empty terms are free. If a scraper is unreliable, that's the developer's problem, not the user's bill.&lt;/p&gt;

&lt;h2&gt;
  
  
  The architecture (no browser)
&lt;/h2&gt;

&lt;p&gt;Google Trends' UI is backed by internal JSON endpoints. You don't need a headless browser — you can talk to them directly:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;GET /trends/api/explore&lt;/code&gt; with your terms → returns &lt;strong&gt;widget tokens&lt;/strong&gt; (one for the timeline, and related-search widgets per term).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /trends/api/widgetdata/multiline?token=…&lt;/code&gt; → interest over time.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /trends/api/widgetdata/relatedsearches?token=…&lt;/code&gt; → related queries.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;No Chrome, no Puppeteer. Direct HTTP is why it runs in ~1.5s locally instead of minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug: it worked locally, failed on the platform
&lt;/h2&gt;

&lt;p&gt;Locally (running from my home IP, no proxy): flawless. Timeline, related queries, everything.&lt;/p&gt;

&lt;p&gt;On Apify (behind a datacenter proxy): &lt;code&gt;explore&lt;/code&gt; succeeded, &lt;code&gt;timeline&lt;/code&gt; succeeded... but &lt;strong&gt;related queries silently failed&lt;/strong&gt; for every term. Then when I switched to residential proxies to "fix" it, it got &lt;em&gt;worse&lt;/em&gt; — now even the timeline failed with &lt;code&gt;blocked&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That combination made no sense to me at first:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;explore&lt;/th&gt;
&lt;th&gt;timeline&lt;/th&gt;
&lt;th&gt;related&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Home IP (no proxy)&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Datacenter proxy&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Residential proxy&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If residential IPs are "better," why did they break &lt;em&gt;more&lt;/em&gt;?&lt;/p&gt;

&lt;h2&gt;
  
  
  The root cause: widget tokens are bound to the IP that requested them
&lt;/h2&gt;

&lt;p&gt;Here's the thing nobody tells you: the widget tokens Google hands you in step 1 are &lt;strong&gt;tied to the IP address that made the &lt;code&gt;explore&lt;/code&gt; call&lt;/strong&gt;. When you then call the &lt;code&gt;multiline&lt;/code&gt; / &lt;code&gt;relatedsearches&lt;/code&gt; endpoints with those tokens, Google checks that the request comes from the &lt;strong&gt;same IP&lt;/strong&gt;. Different IP → token rejected → &lt;code&gt;blocked&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now the table makes sense:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No proxy:&lt;/strong&gt; every request comes from one IP (mine). Everything validates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Datacenter proxy:&lt;/strong&gt; small IP pool, so &lt;code&gt;explore&lt;/code&gt; and &lt;code&gt;timeline&lt;/code&gt; sometimes landed on the same IP by luck — but the parallel related calls hit fresh IPs and got rejected.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Residential proxy:&lt;/strong&gt; &lt;em&gt;huge&lt;/em&gt; rotating IP pool, so even the very next request after &lt;code&gt;explore&lt;/code&gt; came from a different IP. Even the timeline broke.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The "better" proxy broke things precisely &lt;em&gt;because&lt;/em&gt; it rotated IPs more aggressively.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: pin one sticky session per run
&lt;/h2&gt;

&lt;p&gt;The fix is to force every request in a single run through the &lt;strong&gt;same IP&lt;/strong&gt; by pinning a proxy session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;proxy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Actor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createProxyConfiguration&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;groups&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;RESIDENTIAL&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sessionId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`gt&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Every request in this run reuses the same IP:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;proxyUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sessionId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One sticky session → &lt;code&gt;explore&lt;/code&gt;, &lt;code&gt;timeline&lt;/code&gt;, and &lt;code&gt;related&lt;/code&gt; all come from the same IP → tokens stay valid. Result after the fix, on the platform:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;chatgpt&lt;/code&gt;: 53 weekly data points, 16 top related queries, 3 rising&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gemini&lt;/code&gt;: 53 data points, 25 top, 18 rising&lt;/li&gt;
&lt;li&gt;~16s end to end for a 2-term comparison&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The lesson generalizes beyond Google Trends: &lt;strong&gt;any two-step "get a token, then use the token" API can be IP-bound&lt;/strong&gt;. If step 2 fails behind a proxy but step 1 succeeds, suspect IP-pinned tokens before you suspect rate limiting.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pricing angle
&lt;/h2&gt;

&lt;p&gt;Because I only charge for terms that return validated data, I had to make the billing code honest: a term with no search volume comes back from Google as all-zeros with a &lt;code&gt;hasData: false&lt;/code&gt; flag, not an empty array. If you don't check &lt;code&gt;hasData&lt;/code&gt;, you'll "successfully" return a series of zeros and charge for a term that had no data. That check is the difference between "no result = no charge" being a slogan and being true.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Google Trends widget tokens are &lt;strong&gt;IP-bound&lt;/strong&gt; — pin a sticky proxy session for the whole run.&lt;/li&gt;
&lt;li&gt;Test scrapers &lt;strong&gt;on the actual deployment target&lt;/strong&gt;, not just locally. This bug was invisible on my home IP.&lt;/li&gt;
&lt;li&gt;Residential ≠ automatically better. Rotation can break session-bound flows.&lt;/li&gt;
&lt;li&gt;If you charge per result, respect the provider's &lt;code&gt;hasData&lt;/code&gt; flags or your "free on failure" promise is a lie.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The scraper is live here if you want to try it (pay-per-result, failed terms are free): &lt;strong&gt;&lt;a href="https://apify.com/swiftscrape/google-trends-fast-scraper" rel="noopener noreferrer"&gt;Fast Google Trends Scraper on Apify&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Happy to answer questions about the internal endpoints or the token behavior in the comments.&lt;/p&gt;

</description>
      <category>api</category>
      <category>webscraping</category>
      <category>seo</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
