scraperapi-cli
v1.0.0
Published
Official CLI for ScraperAPI — scrape any URL, run async jobs, extract structured data, and manage crawls from your terminal.
Downloads
135
Readme
ScraperAPI CLI
The official command-line interface for ScraperAPI. Scrape any URL, run async jobs, extract structured data, manage crawls and pipelines — all from your terminal.
Installation
Requires Node.js 18 or higher.
npm install -g scraperapi-cliInstalling from source (until the package is published to npm):
git clone https://github.com/scraperapi/scraperapi-cli
cd scraperapi-cli
npm install
npm run build
npm linknpm link creates a global sapi symlink pointing at your local build. Re-run npm run build after any source changes.
Quick Start
# 1. Configure your API key (from https://dashboard.scraperapi.com)
sapi init
# 2. Scrape a page
sapi scrape https://example.com
# 3. Pipe output into another tool
sapi scrape https://example.com --json | jq .statusCodeAuthentication
sapi looks for your API key in this order:
--api-key <key>flag on any commandSCRAPERAPI_API_KEYenvironment variable- Config file written by
sapi init(~/.config/scraperapi/config.json)
Get your API key from the ScraperAPI dashboard. New accounts include a free trial with 5,000 credits.
Commands
sapi init
Interactive setup. Prompts for your API key, validates it, and saves it to the config file.
sapi init
# or non-interactively:
sapi init --api-key YOUR_KEYsapi scrape <url>
Scrape a URL synchronously and print the response body. See the supported parameters reference for full details on all options.
sapi scrape https://example.com
sapi scrape https://example.com --render # JavaScript rendering
sapi scrape https://example.com --render --wait-for "#main"
sapi scrape https://example.com --country gb # UK IP
sapi scrape https://example.com --premium # residential proxies
sapi scrape https://example.com --autoparse --json
sapi scrape https://example.com --async # submit as background job| Flag | Description |
| ------------------ | ---------------------------------------------- |
| --render | JavaScript rendering |
| --premium | Residential proxies |
| --ultra-premium | Advanced anti-bot bypass |
| --screenshot | Capture PNG screenshot |
| --autoparse | Return structured JSON |
| --country <cc> | Geotarget (ISO 3166-1, e.g. us, gb, de) |
| --device <type> | mobile or desktop user-agent |
| --output <fmt> | html, markdown, text, json, csv |
| --session <n> | Sticky session (reuse same IP) |
| --wait-for <sel> | CSS selector to wait for (requires --render) |
| --timeout <sec> | Request timeout in seconds (default: 70) |
| --async | Submit as async job, print job ID and exit |
| --json | Output raw JSON to stdout |
Some flags incur additional credit costs per request. See the supported parameters reference for the full breakdown.
sapi cost <url>
Check the credit cost of a scrape request without executing it. Accepts the same flags as sapi scrape (except --async and --timeout).
sapi cost https://example.com
sapi cost https://example.com --render --premium
sapi cost https://example.com --render --jsonPrints the number of credits the request would consume:
25 creditssapi jobs
Manage async scrape jobs. Use these when scraping large volumes or when you don't need an immediate response.
sapi jobs list # list all jobs
sapi jobs get <jobId> # poll until done, print result
sapi jobs get <jobId> --no-poll # fetch current status without polling
sapi jobs cancel <jobId> # cancel a running job
sapi jobs batch urls.txt # submit up to 50,000 URLs from a fileurls.txt should contain one URL per line. See the batch requests docs for more on bulk submission.
sapi structured
Fetch pre-parsed structured data from supported platforms — no need to write a parser. See the Structured Data Endpoints docs for response schemas and supported options.
Amazon
sapi structured amazon product https://amazon.com/dp/B09XYZ
sapi structured amazon search "wireless headphones"
sapi structured amazon offers https://amazon.com/dp/B09XYZ
sapi structured amazon reviews https://amazon.com/dp/B09XYZsapi structured google serp "best espresso machine"
sapi structured google news "artificial intelligence"
sapi structured google jobs "software engineer remote"
sapi structured google shopping "standing desk"
sapi structured google maps "coffee shops near me"Walmart / eBay / Redfin
sapi structured walmart product https://walmart.com/ip/123456
sapi structured ebay product https://ebay.com/itm/123456
sapi structured redfin listing https://redfin.com/home/12345
sapi structured redfin search "Austin TX"
sapi structured redfin agents "Portland OR"All structured commands support --json for raw JSON output.
sapi crawler
Crawl an entire domain and collect all discovered URLs. See the Crawler docs for configuration options and job lifecycle details.
sapi crawler start example.com # start a crawl
sapi crawler status <jobId> # check progress
sapi crawler results <jobId> # list discovered URLs
sapi crawler results <jobId> --json # as JSON arraysapi pipeline
Manage DataPipeline bulk scraping projects. DataPipeline handles scheduling, retries, and result storage for large-scale recurring jobs.
sapi pipeline list # list your projects
sapi pipeline run <projectId> # trigger a run
sapi pipeline status <jobId> # check run status
sapi pipeline results <jobId> # fetch resultssapi account
Inspect your account usage and manage API keys. Credit usage and limits are also visible in the ScraperAPI dashboard.
sapi account # show credits and usage
sapi account keys list
sapi account keys create
sapi account keys revoke <keyId>sapi config
Read and write config defaults without re-running sapi init.
sapi config list
sapi config get api_key
sapi config set default_country gb
sapi config set default_timeout 90Settable keys: api_key, default_country, default_output_format, default_timeout.
Output & Piping
By default, sapi prints human-readable output to stdout and all non-data output (warnings, prompts, progress) to stderr.
When stdout is a pipe, sapi automatically switches to JSON mode:
sapi scrape https://example.com | jq .body
sapi jobs list | jq '.[].status'
sapi structured google serp "nodejs" | jq '.organic_results[0].title'Force JSON mode explicitly with --json:
sapi account --jsonForce a specific output format with --output:
sapi scrape https://example.com --output markdownEnvironment Variables
| Variable | Description |
| -------------------- | ------------------------------- |
| SCRAPERAPI_API_KEY | API key (overrides config file) |
Requirements
- Node.js 18+
- A ScraperAPI account and API key
