이 튜토리얼은 Python에서 Google에 쿼리를 보내고 깔끔한 구조화된 결과를 얻는 방법을 보여줍니다 — 2026년 가장 저렴한 Google Search API인 serp.cheap를 사용합니다.
설치
pip install requests
최소 예제
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"]}')
재시도 기능이 있는 재사용 가능한 클라이언트
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
페이지네이션
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
각 페이지는 별도로 과금되는 요청입니다 — 필요할 때만 지연 로딩하세요. 자세한 내용은 페이지네이션을 참고하세요.
비용 관리
stats.cost는 크레딧 단위입니다(1 = $0.0001). 캐시 적중은 3 크레딧, 신규 조회는 6 크레딧입니다. 반복되는 쿼리는 자동으로 절반 가격에 캐시에서 제공됩니다.