/scraperapi:scraperapi-python-sdkfrom ScraperAPI
Best-practices reference for the ScraperAPI Python SDK. Covers client setup, request parameters, escalation ladder (standard → render → premium → ultra_premium), async jobs, structured data endpoints, error handling, and credit budgeting.
Ships in ScraperAPI. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Requires: Python 3.10+ (the SDK uses list | tuple annotations, so importing it fails on older versions), pip install scraperapi-sdk, a ScraperAPI API key.
from scraperapi_sdk import ScraperAPIClient
client = ScraperAPIClient("YOUR_API_KEY")
Replace YOUR_API_KEY with your key from https://dashboard.scraperapi.com. Never commit a real key to source control.
Pick the right call pattern before writing any code.
| Situation | Pattern |
|---|---|
| Single URL, response needed immediately | client.get() — synchronous |
| 20+ URLs, or single URL that often times out | Async Jobs API — requests.post() to async.scraperapi.com/jobs |
| Supported platform (Amazon, Google, Walmart, eBay, Redfin) | Structured Data endpoint — api.scraperapi.com/structured/<vertical> |
| Page loads content via JavaScript (React, Vue, Angular) | client.get() with render=True |
| Site blocks standard proxies | client.get() with premium=True |
Use the sync SDK for simple, single-URL work. For batches, the SDK has ScraperAPIAsyncClient (single jobs only); use raw requests for /batchjobs or when you need control over polling — see Async Jobs.
# Simple scrape. Returns str for text/HTML, dict for JSON (autoparse, output_format=json), bytes otherwise
html = client.get(url="https://example.com/")
# With parameters
html = client.get(
url="https://example.com/",
params={"render": True, "country_code": "us"}
)
# Render JavaScript before returning HTML
# Use when: page uses React/Vue/Angular, or initial scrape returns empty/partial content
# Cost: 10 credits per request (instead of 1)
html = client.get(url="https://spa-site.com/", params={"render": True})
# Wait for a specific element before capturing (requires render=True)
# Use when: content loads lazily and simple render still misses it
html = client.get(
url="https://spa-site.com/",
params={"render": True, "wait_for_selector": ".product-list"}
)
# Capture a screenshot (auto-enables rendering)
html = client.get(url="https://example.com/", params={"screenshot": True})
Start without render=True. Add it only when the response is missing expected content — it increases cost and latency.
# Route through a specific country — no extra cost
html = client.get(url="https://example.com/", params={"country_code": "us"})
# Premium residential/mobile proxies — for sites that block datacenter IPs
# Cost: 10 credits per request (25 with render=True)
html = client.get(url="https://hard-site.com/", params={"premium": True})
# Ultra-premium — for the toughest anti-bot protections
# Cost: 30 credits per request (75 with render=True)
# Note: incompatible with custom headers (keep_headers is ignored)
html = client.get(url="https://hardest-site.com/", params={"ultra_premium": True})
premium and ultra_premium are mutually exclusive — never set both. Escalate gradually:
standard (1 cr) → render (10 cr) → premium (10 cr) → premium+render (25 cr) → ultra_premium (30 cr).
# Reuse the same proxy IP across multiple requests
# Use for: multi-page flows, pagination, login-state scraping
# Sessions expire 15 minutes after last use; any integer is a valid session ID
html1 = client.get("https://example.com/page1", params={"session_number": 42})
html2 = client.get("https://example.com/page2", params={"session_number": 42})
session_number can't be combined with premium or ultra_premium.
# Forward your own headers to the target site
# Note: keep_headers is incompatible with ultra_premium=True
html = client.get(
url="https://example.com/",
params={"keep_headers": True},
headers={"Accept-Language": "en-US", "Referer": "https://google.com"}
)
# Emulate mobile or desktop user-agent
html = client.get(url="https://example.com/", params={"device_type": "mobile"})
# Default: raw HTML
html = client.get(url="https://example.com/")
# Structured JSON for supported sites (Amazon, Google, etc.)
# autoparse extracts fields like title, price, reviews automatically
data = client.get(url="https://amazon.com/dp/B09V3KXJPB", params={"autoparse": True})
# Markdown — useful for LLM pipelines
text = client.get(url="https://docs.example.com/", params={"output_format": "markdown"})
# Plain text
text = client.get(url="https://example.com/", params={"output_format": "text"})
# Binary content (PDFs, images)
content = client.get(url="https://example.com/report.pdf", params={"binary_target": True})
Always start cheapest. Move up only when the site blocks the previous tier.
from scraperapi_sdk import ScraperAPIException
def scrape_with_escalation(url):
for params in [
{}, # 1 credit
{"render": True}, # 10 credits
{"premium": True}, # 10 credits
{"premium": True, "render": True}, # 25 credits
{"ultra_premium": True}, # 30 credits
]:
try:
result = client.get(url=url, params=params)
except ScraperAPIException as e:
resp = getattr(e.original_exception, "response", None)
if resp is not None and resp.status_code in (401, 403):
raise # bad key, out of credits or max_cost hit: a pricier tier won't help
continue # 500 or timeout: try the next tier
if isinstance(result, str) and "<html" in result.lower():
return result
return None
client.get raises on any non-2xx, so each tier needs its own try. Credits above are for a normal site; Google, Amazon and bot-protected sites cost more (see Credit Cost Reference).
Log which tier succeeded so you can start there next time for the same domain.
The sync SDK blocks on each call, and client.get gives up after 55 seconds while ScraperAPI may keep retrying for up to 70 (requests cancelled before 70s are still charged). For slow targets, call client.make_request(url=..., params=..., timeout=70), which returns the raw requests.Response. For 20+ URLs, use the async endpoint: it submits jobs in the background and lets you poll or receive webhooks.
The SDK's ScraperAPIAsyncClient covers single jobs:
from scraperapi_sdk import ScraperAPIAsyncClient
async_client = ScraperAPIAsyncClient("YOUR_API_KEY")
job = async_client.create("https://example.com/", api_params={"render": True})
# wait() checks max_retries times, then returns the job as-is, even if it is still running
data = async_client.wait(job["id"], cooldown=10, max_retries=60)
if data["status"] == "finished":
body = data["response"]["body"]
For more control, or for /batchjobs, use requests directly:
import requests, time
API_KEY = "YOUR_API_KEY"
def submit_job(url, extra_params=None):
payload = {
"apiKey": API_KEY,
"url": url,
"apiParams": extra_params or {},
"expectUnsuccessReport": True, # without it, a job that fails never reaches "failed"
}
r = requests.post("https://async.scraperapi.com/jobs", json=payload, timeout=10)
r.raise_for_status()
return r.json() # {"id": "...", "status": "running", "statusUrl": "..."}
def poll_job(job, max_wait=600, interval=10):
# Jobs can keep retrying for up to 24h; pick a deadline that fits your use case
deadline = time.time() + max_wait
while time.time() < deadline:
data = requests.get(job["statusUrl"], timeout=10).json()
if data["status"] == "finished":
return data["response"]["body"]
if data["status"] == "failed":
raise RuntimeError(f"Job failed: {job['id']}")
time.sleep(interval)
raise TimeoutError(f"Job {job['id']} did not finish in {max_wait}s")
# Batch pattern: submit all, then collect, so one bad job doesn't lose the rest
urls = ["https://example.com/page1", "https://example.com/page2"]
jobs = [submit_job(u) for u in urls]
results = {}
for j in jobs:
try:
results[j["url"]] = poll_job(j)
except (RuntimeError, TimeoutError) as e:
results[j["url"]] = None
print(e)
Use webhooks ("callback": {"type": "webhook", "url": "https://yourapp.com/cb"}) when you control a server — eliminates polling entirely. See async docs.
For very large batches (up to 50,000 URLs), use https://async.scraperapi.com/batchjobs with a "urls": [...] array.
Use these instead of scraping raw HTML when the target platform is supported. They return clean JSON and require no parsing logic; they're billed at the target site's rate (5 credits for Amazon, 25 for Google).
import requests
API_KEY = "YOUR_API_KEY"
def structured_get(vertical, params):
"""Call a structured data endpoint synchronously."""
url = f"https://api.scraperapi.com/structured/{vertical}"
r = requests.get(url, params={"api_key": API_KEY, **params}, timeout=70)
r.raise_for_status()
return r.json()
# Google SERP
results = structured_get("google/search", {"query": "best Python web scrapers"})
# Amazon product details
product = structured_get("amazon/product", {"asin": "B09V3KXJPB"})
# Walmart product search
items = structured_get("walmart/search", {"query": "standing desk", "tld": "com"})
Supported verticals: google/search, google/news, google/jobs, google/shopping,
google/mapssearch, amazon/product, amazon/search, amazon/offers,
walmart/product, walmart/search, walmart/category, walmart/review,
ebay/product, ebay/search/v2, redfin/forsale, redfin/forrent, redfin/search, redfin/agent.
The SDK also has shortcut methods: client.google.search(query), client.amazon.product(asin), client.walmart.product(product_id), client.ebay.searchV2(query), client.redfin.forsale(url) and so on. They send geotargeting as country, while the endpoints document country_code, so use structured_get above when you need a specific country.
See structured data docs for required parameters per vertical.
The SDK wraps every failure (HTTP errors, timeouts, connection errors) in ScraperAPIException. The original requests exception is on e.original_exception; for HTTP errors, its .response carries the status code.
from scraperapi_sdk import ScraperAPIClient, ScraperAPIException
client = ScraperAPIClient("YOUR_API_KEY")
def scrape(url, params=None):
try:
return client.get(url=url, params=params or {})
except ScraperAPIException as e:
resp = getattr(e.original_exception, "response", None)
if resp is None:
# Timeout or connection error: no status code. Retry, or use make_request(timeout=70)
raise RuntimeError(f"Network error or timeout: {e.original_exception}") from e
status = resp.status_code
if status == 401:
raise ValueError("Invalid API key — check your API key") from e
if status == 403:
# Credits exhausted, or the request would cost more than max_cost. Retrying won't help
raise RuntimeError("Out of credits or over max_cost — check https://dashboard.scraperapi.com/billing (don't retry)") from e
if status == 429:
# Concurrent request limit — back off and retry
raise RuntimeError("Rate limit — reduce concurrency or switch to async") from e
if status == 500:
# ScraperAPI already retried for 70s (not charged) — retry; on protected sites escalate to premium/ultra_premium
raise RuntimeError("Request failed after retries — retry or escalate") from e
raise
Status code reference: 200 success, 400 malformed request, 401 bad key, 403 credits exhausted or max_cost exceeded (don't retry), 404 target not found (charged),
429 concurrency limit, 500 failed after 70s of retries (not charged — retry, then escalate to premium/ultra_premium on protected sites).
| Request type | Credits |
|---|---|
| Standard | 1 |
render=True | 10 |
premium=True | 10 |
premium=True + render=True | 25 |
ultra_premium=True | 30 |
ultra_premium=True + render=True | 75 |
Those are the costs on a normal site. Some sites cost more per request:
| Site | Credits |
|---|---|
| Amazon, Walmart, eBay | 5 |
| Google, Bing (all subdomains) | 25 |
| 30 | |
| Sites behind Cloudflare, DataDome, PerimeterX or Akamai | 10 |
Combined costs vary by site; check the exact price with /account/urlcost or the sa-credit-cost header before a large run.
You're charged for 200 and 404 responses, and for requests you cancel before ScraperAPI's 70s
of retries finish. Each response's sa-credit-cost header shows what it cost; preview a cost
without spending credits with GET https://api.scraperapi.com/account/urlcost?api_key=...&url=...
(it accepts the same parameters). Source: https://docs.scraperapi.com/getting-started/quick-start/credits-and-requests-costs
Add "max_cost": N to any request to cap credit spend — returns 403 if the request would exceed N credits.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
20 skills in this plugin
/scraperapi-agent-onboardingEntry point for agents and developers new to ScraperAPI. Read first when integrating ScraperAPI into an agent or app, setting up the MCP server for Claude Code or other LLM tools, choosing the right ScraperAPI product, or getting an API key. Trigger on: "how do I use ScraperAPI", "set up ScraperAPI", "connect ScraperAPI to Claude", "which ScraperAPI product should I use", "get web data for my agent", "add web scraping to my project", "ScraperAPI getting started". After reading, route to the narrower skill that owns the chosen path. If the user already named a language or SDK, n8n, Zapier, or the sapi CLI, use that skill directly instead.
Note: Transmits user-supplied queries, URLs, and content to ScraperAPI.
/scraperapi-asyncReference for ScraperAPI's Async Jobs REST API: submit scraping jobs in the background and get results by polling or webhook, including batch jobs. Consult when the user is scraping many URLs, needs non-blocking requests, or wants webhook delivery. Use when user asks: "how do I scrape 1000 URLs with ScraperAPI", "ScraperAPI async jobs", "batch scraping with ScraperAPI", "submit a scraping job and poll for results", "ScraperAPI webhook callback", "ScraperAPI batchjobs endpoint". Covers single and batch jobs, webhook callbacks, apiParams, async-only parameters, binary responses, retention, and error handling. It is language-agnostic: for SDK client code, use the language's SDK skill; to crawl a whole site by following links, use scraperapi-crawler.
Note: Transmits user-supplied queries, URLs, and content to ScraperAPI.
/scraperapi-cliReference for the official ScraperAPI command-line tool (`sapi`, package `scraperapi-cli`). Use this skill whenever the user wants to scrape, run async jobs, fetch structured data or check credits from a terminal or shell script. Trigger on: "scrape this URL from the terminal", "use sapi to fetch X", "ScraperAPI CLI", "ScraperAPI from bash", "sapi scrape", "sapi jobs", "pipe ScraperAPI into jq", "scrape from a Makefile / cron / CI", "check my ScraperAPI credits from the command line", "scrape 10000 URLs from a file". Covers install, auth, commands, JSON and piping behaviour, cost checks and shell recipes. Not for writing scraper code: for a new scraper script use scraperapi-scraper-builder, and for code that calls ScraperAPI use the language's SDK skill.
Note: Transmits user-supplied queries, URLs, and content to ScraperAPI.
/scraperapi-crawlerProduct-usage reference for ScraperAPI's Crawler — crawl an entire site or section by following links automatically. Consult when the user needs to extract data from many pages of a site without knowing the URLs upfront. Use when user asks: "crawl an entire website with ScraperAPI", "scrape all pages on a domain", "follow links and scrape each page", "how do I use the ScraperAPI crawler API", "scrape a site map", "extract data from every product page on a site", "ScraperAPI crawler job API". Covers job creation, URL regex patterns, depth vs budget, per-page scraping parameters, job states, webhooks, scheduling, and credit costs. Also invoke when the user is building a site-wide scraper and asks which ScraperAPI product to use.
Note: Transmits user-supplied queries, URLs, and content to ScraperAPI.
/scraperapi-datapipelineProduct-usage reference for ScraperAPI's DataPipeline — managed, scheduled scraping projects that run automatically and deliver results to a webhook or dashboard download. Consult when the user needs recurring scraping, has a large list of URLs/ASINs/queries to process, or wants to avoid building and maintaining their own scraping infrastructure. Use when user asks: "schedule recurring scraping with ScraperAPI", "ScraperAPI DataPipeline", "how do I run a scraping project on a schedule", "scrape 10000 ASINs automatically", "ScraperAPI managed scraping project", "set up a ScraperAPI pipeline", "deliver scraping results to a webhook automatically". Covers project types, input methods, scheduling, output delivery, the DataPipeline API, job management, and credit costs.
Note: Transmits user-supplied queries, URLs, and content to ScraperAPI.
/scraperapi-java-sdkBest-practices reference for the ScraperAPI Java SDK (com.scraperapi:sdk Maven artifact). Consult whenever the user is writing, debugging, or reviewing Java code that calls ScraperAPI. Use when user asks: "scrape a website with Java and ScraperAPI", "ScraperAPI Java example", "how do I add ScraperAPI to my Maven project", "Java ScraperAPI render", "ScraperAPI Java fluent API", "ScraperAPI Java premium proxy", "ScraperAPI Java error handling", "ScraperAPI Java retry". Covers Maven/Gradle setup, the fluent builder API, all request parameters, the escalation ladder, async jobs, structured data calls, error handling, and credit costs.
Note: Transmits user-supplied queries, URLs, and content to ScraperAPI.
npx claudepluginhub scraperapi/scraperapi-skills --plugin scraperapiOther plugins' skills for the same job