Autom

Handle pagination

Fetch the next pages of results with the page parameter.

Use the page parameter to fetch subsequent pages. The response includes a pagination object with has_next_page and next page number.

import os
import requests

API_KEY = os.environ["AUTOM_API_KEY"]


def get(path, params):
    response = requests.get(f"https://api.autom.dev{path}", headers={"x-api-key": API_KEY}, params=params)
    if not response.ok:
        raise SystemExit(f"Error {response.status_code}: {response.text}")
    return response.json()


def fetch_all_results(query, max_pages=3):
    all_results = []
    for page in range(1, max_pages + 1):
        data = get("/v1/google/search", {"query": query, "gl": "us", "hl": "en", "page": page})
        all_results.extend(data.get("organic_results", []))
        if not data.get("pagination", {}).get("has_next_page"):
            break
    return all_results


for result in fetch_all_results("best python web scraping libraries"):
    print(f"[{result['position']}] {result['title']} — {result['link']}")

Use the gl parameter to target a specific country (e.g. fr for France, de for Germany) and hl for the language of results. This is essential for accurate local rank tracking.