A terminal request is easy to make. A dependable SERP data pipeline needs a lot more: a permitted data source, consistent fields, repeatable geography and device settings, and an explicit distinction between search results and the pages linked from them.
This guide shows where cURL fits and where it does not.
TL;DR
- cURL is great for debugging an endpoint you are allowed to call.
- Google says automated Search queries without express permission violate its policies.
- The Custom Search JSON API serves configured Programmable Search Engines, not every consumer Google Search feature. Its current notice says existing customers only and scheduled end date January 1, 2027.
- A third-party SERP API can return structured result data; a crawler handles fetching and extracting the linked pages.
- A browser automation library does not grant permission to automate a service.
1. Inspect an authorized HTTP endpoint with cURL
For an endpoint where you have permission to make a request, collect headers and a response body separately:
curl --silent --show-error --location \
--connect-timeout 10 --max-time 30 \
--dump-header response-headers.txt \
--output response.html \
--write-out 'status=%{http_code} type=%{content_type} bytes=%{size_download}\n' \
'https://example.com/'
This makes it easier to debug redirects, timeout behavior, content type, and unexpectedly empty responses. It is not a SERP API, and an HTTP success status does not prove the content is complete or appropriate for your use.
Google states that automated queries to Search without express permission—including scraping results for rank checking—violate its machine-generated traffic policy. Do not turn the command into a loop that automates consumer search pages.
2. Call the official API when your account and use case qualify
The Custom Search JSON API returns JSON for a configured Programmable Search Engine. If you already have access and the scope fits, a request looks like this:
export GOOGLE_API_KEY='load-this-from-your-secret-manager'
export GOOGLE_CSE_ID='your-programmable-search-engine-id'
curl --get 'https://www.googleapis.com/customsearch/v1' \
--data-urlencode "key=$GOOGLE_API_KEY" \
--data-urlencode "cx=$GOOGLE_CSE_ID" \
--data-urlencode 'q=python pagination' \
--data-urlencode 'num=10' \
--output results.json
Do not commit keys to Git or paste them into logs. The response represents the configured search engine and should not be treated as a complete replica of all ordinary Google Search result features. Check Google’s API availability notice before selecting it: it says the API is available to existing customers and is scheduled to end on January 1, 2027.
3. Use a SERP API for scheduled, structured search data
If the job is rank tracking or repeated keyword research, evaluate a provider whose product is designed to return SERP records. Confirm its supported engine, locations, language, device types, result fields, limits, retention, and pricing. Do not assume one vendor’s schema transfers to another.
For example, SerpApi documents a Google Search API request using its own parameter names:
export SERPAPI_KEY='load-this-from-your-secret-manager'
curl --silent --show-error --get 'https://serpapi.com/search.json' \
--data-urlencode 'engine=google' \
--data-urlencode 'q=python pagination' \
--data-urlencode 'google_domain=google.com' \
--data-urlencode 'gl=us' \
--data-urlencode 'hl=en' \
--data-urlencode 'device=desktop' \
--data-urlencode "api_key=$SERPAPI_KEY" \
--output serp.json
See the provider API documentation for the contract. Before you build, test a handful of representative queries and verify whether the returned fields match your reporting requirements.
Keep SERP discovery separate from page crawling
A robust pipeline has two independent contracts:
- SERP provider: query, location, device, rank, result URL, and collection time.
- Page fetcher: permitted URL, extracted text or Markdown, metadata, response status, and fetch timestamp.
The first component tells you what appeared in a result set. The second retrieves content from selected sites. Keeping them separate makes retries and vendor changes easier to reason about. A web crawling API can help with the second stage, but it does not provide Google rankings.
Practical acceptance checks
Before scheduling a job, validate:
- Does your source permit the exact collection use case?
- Can you request the same geography, language, and device consistently?
- Are the fields in your output documented and stable?
- What happens on timeouts, rate limits, partial results, and provider errors?
- Are API keys stored and rotated safely?
- Can you estimate the cost from your real query frequency?
Avoid treating status code 200 as the only success metric. Check that the expected result array exists, required fields are populated, and the timestamp and query settings are stored with each record.
Discussion: What fields do you actually need to persist for your SERP workflow—rank and URL only, or location, device, snippets, and feature metadata too?
References: Google machine-generated traffic policy · Custom Search JSON API · API availability notice
Top comments (0)