Skip to content

About

Google Autocomplete Scraper: Google's search suggestions, expandable a-z

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Google Autocomplete Scraper API by Scrapier

Google Autocomplete Scraper for Python

Get Google's autocomplete suggestions for a seed keyword as JSON, expandable with a-z prefixes and suffixes. Built on the Scrapier API: one HTTPS request, no headless browser to run, no parser to maintain.

tests Python 3.9+ Get a free API key

Quickstart · Fields · CLI · FAQ

Quickstart

  1. Get an API key from the Scrapier dashboard. No credit card needed to start.

  2. Install:

    pip install git+https://github.com/get-scrapier/Google-Autocomplete-Scraper
  3. Run:

from scrapier_google_autocomplete import GoogleAutocomplete

client = GoogleAutocomplete(api_key="sk_live_...")   # or set SCRAPIER_API_KEY

# the expansion is what makes this useful
rows = client.autocomplete("machine learning",
                           use_prefix=True, use_suffix=True)
phrases = [rows[i][f"suggestion_{n:02d}"]
           for i in range(len(rows)) for n in range(1, 11)
           if rows[i].get(f"suggestion_{n:02d}")]

The same code is in examples/quickstart.py.

Use cases

  • Keyword research
  • Content ideas
  • SEO planning
  • Search demand research

What it does

Returns Google's autocomplete suggestions for a seed term. With the a-z expansions on, one seed becomes hundreds of phrases -- the closest publicly visible signal of Google search demand.

Rows are wide rather than nested: each holds up to ten suggestions in numbered fields. :meth:suggestions flattens them for you.

Wraps the Scrapier google-autocomplete endpoint.

Calling it

rows = client.autocomplete(query)   # a list
page = client.autocomplete_page(query)
page.items          # the same rows
page.data           # the whole envelope

One request. This endpoint does not paginate, so there is no cursor and no iter_ method.

Fields you actually get back

Observed on live responses, not copied from a schema.

Field Notes
suggestion_01 … suggestion_10 up to ten suggestions, as ten separate fields rather than a list
keyword the expansion this row came from
position row index

Options

Argument What it does
use_prefix Also query a <seed> through z <seed>. Pass True explicitly -- see the quirks.
use_suffix The same with the letter appended. Also needs passing explicitly.
language Language name or hl code -- "English" and "en" both work here.
country Country name or gl code -- "United States" and "us" both work.

Quirks worth knowing

The expansions are documented as on by default but behave as off when omitted. Measured on "machine learning": omitting them gives 1 row and 10 suggestions, while use_prefix=True, use_suffix=True gives 53 rows and 517. This client sends only what you pass rather than second-guessing the server, so ask for the expansion when you want it. It is one request either way, so the wide call costs the same in credits and only takes longer.

Rows are wide, not nested. Ten numbered suggestion_NN fields per row, which is awkward to consume -- read them in a loop over range(1, 11), or flatten them yourself.

It does not paginate: one request, all the rows.

Async

AsyncGoogleAutocomplete exposes every method GoogleAutocomplete does, with identical arguments.

import asyncio
from scrapier_google_autocomplete import AsyncGoogleAutocomplete

async def main():
    async with AsyncGoogleAutocomplete() as client:
        rows = await client.autocomplete(query)

asyncio.run(main())

Bulk jobs

For hundreds of inputs, submit one background job instead of paging:

job = client.bulk([...], max_items=1000)   # up to 10,000 per input
print(job.job_id, job.status)

rows = job.wait(timeout=1800, poll_interval=5)

Reattach from another process with client.job(job_id), then read job.data.

Submits are deduplicated server-side on the request parameters, so an identical submit returns the job the first one created — including when that job failed. Vary a parameter to force a fresh attempt.

Errors

Everything derives from ScrapierError, so one except can catch the lot while you still get to be specific when it matters.

from scrapier_google_autocomplete import InsufficientCreditsError, RateLimitError, ScrapierError

try:
    rows = client.autocomplete(query)
except InsufficientCreditsError as exc:
    print(f"out of credits: {exc.balance} left, {exc.required} needed")
except RateLimitError as exc:
    print(f"slow down for {exc.retry_after}s")
except ScrapierError as exc:
    print(f"something else: {exc}")
Exception When
ConfigurationError no API key, or a reserved parameter was passed
TransportError the request never got a response
BadRequestError 400 — bad input
AuthenticationError 401 — bad or missing key
InsufficientCreditsError 402 with a balance — carries .balance and .required
NotFoundError 404
RateLimitError 429 — carries .retry_after
ScrapeTimeoutError 504 — the scrape itself ran out of time
ServiceUnavailableError 503
ServerError 5xx
JobFailedError a bulk job finished in failed — carries .errors
APIError the base for anything with a status code

429, 503, 5xx and transport failures are retried automatically with jittered backoff that honours Retry-After. 400, 401, 404 and a 402 about your balance are not — retrying those only wastes time.

Command line

export SCRAPIER_API_KEY=sk_live_...

scrapier-google-autocomplete <query>

JSON on stdout and nothing else, so it pipes. Global flags (--api-key, --base-url, --timeout, --jsonl, --indent) work anywhere on the line. Exit codes: 0 success, 2 usage or configuration, 3 API error.

Client reference

GoogleAutocomplete(
    api_key=None,        # falls back to $SCRAPIER_API_KEY
    base_url=None,       # falls back to $SCRAPIER_BASE_URL, then the default
    timeout=120.0,
    max_retries=3,       # for 429/503/5xx and transport failures
    http_client=None,    # bring your own httpx.Client
)

The key is sent in the X-API-Key header only — never in a URL or a request body, so it will not end up in a proxy log.

Every call also accepts method="GET" if you would rather the parameters went in the query string, use_proxy=True to route the scrape through Scrapier's proxy pool, and raw_data=True to get the upstream payloads instead of parsed rows.

Python 3.9+. The only dependency is httpx. Ships py.typed.

FAQ

Is this Google Autocomplete Scraper free?

The client code is MIT-licensed. It needs a Scrapier API key, and requests are billed in credits; failed requests are not billed. See pricing. You can start without a credit card.

Do I need proxies or a headless browser?

No. The scrape runs on Scrapier's servers and returns JSON.

How do I scrape in bulk?

Use bulk jobs: submit many inputs as one background job, then job.wait().

Can an AI agent use this?

Yes. See AGENTS.md, or connect the Scrapier MCP server.

More from Scrapier

180+ endpoints across 35+ platforms: browse them all.

Support

Open an issue or read the docs.

License

MIT. See LICENSE.

About

Google Autocomplete Scraper: Google's search suggestions, expandable a-z

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages