Questo tutorial mostra come interrogare Google da Python e ottenere risultati strutturati e puliti — usando serp.cheap, la Google Search API più economica del 2026.
Installazione
pip install requests
Esempio minimo
import requests
resp = requests.post(
"https://api.serp.cheap/v1/search",
headers={"X-API-Key": "YOUR_KEY"},
json={"q": "best electric cars 2026", "gl": "us", "page": 1},
timeout=30,
)
resp.raise_for_status()
for r in resp.json()["organic"]:
print(f'#{r["position"]} {r["title"]} — {r["link"]}')
Un client riutilizzabile con retry
import requests
from requests.adapters import HTTPAdapter, Retry
class SerpClient:
def __init__(self, api_key: str):
self.s = requests.Session()
self.s.headers.update({"X-API-Key": api_key})
retries = Retry(total=4, backoff_factor=1.5,
status_forcelist=[429, 500, 502, 503, 504])
self.s.mount("https://", HTTPAdapter(max_retries=retries))
def search(self, q, gl="us", page=1, tbs=None):
body = {"q": q, "gl": gl, "page": page}
if tbs:
body["tbs"] = tbs
r = self.s.post("https://api.serp.cheap/v1/search", json=body, timeout=30)
r.raise_for_status()
return r.json()
client = SerpClient("YOUR_KEY")
data = client.search("python web scraping", gl="us")
print(data["stats"]) # balance, cost, cached
Paginazione
def all_results(client, q, pages=3, gl="us"):
out = []
for p in range(1, pages + 1):
out += client.search(q, gl=gl, page=p)["organic"]
return out
Ogni pagina è una richiesta fatturata separatamente — recuperala in modo lazy. Altro nella paginazione.
Controllo dei costi
stats.cost è espresso in crediti (1 = $0.0001). Le cache hit costano 3 crediti, le richieste fresh 6. Le query ripetute vengono servite automaticamente dalla cache a metà prezzo.