| name | cli-apify |
| description | Covers effective use of the Apify CLI for web scraping and automation using Actors, datasets, key-value stores, and Crawlee. Covers apify init/run/push/login/call/pull, Actor concepts, pagination, proxy rotation, scheduling, webhooks, and CSV/JSON export. Activates when the user asks about Apify, running or building Actors, cloud web scraping, or extracting data at scale.
|
Apify CLI — Web Scraping & Actor Platform
Repo: https://github.com/apify/apify-cli
The Apify CLI manages Actors — containerized scraping/automation tasks that run
locally or on the Apify cloud. Backed by Crawlee for
browser and HTTP crawling. Pairs naturally with Playwright or Puppeteer for
JS-heavy sites.
When to Activate
Manual triggers:
- "How do I use the Apify CLI?"
- "Create / run / deploy an Apify Actor"
- "Scrape a website and export to CSV"
- "Set up pagination / proxy rotation with Apify"
Auto-detect triggers:
- User wants scalable, cloud-hosted web scraping
- User wants to schedule a scraper or fire webhooks
- User is building a Crawlee-based crawler
- User needs to store/export large scraping datasets
Key Commands
Authentication
apify login
apify login --token <TOKEN>
apify logout
Scaffold & Init
apify create my-actor
apify create my-actor --template=playwright-js
apify init
Local Development
apify run
apify run --purge
apify run --input='{"url":"https://example.com"}'
apify run --input=@input.json
Cloud Operations
apify push
apify push --version-number=1.2
apify call my-actor
apify call my-actor --input=@in.json
apify pull my-actor
apify actor --version
Inspect Outputs
apify datasets ls
apify datasets get-items <datasetId>
apify datasets get-items <datasetId> --format=csv > out.csv
apify key-value-stores ls
apify key-value-stores get-record <storeId> <key>
Core Concepts
Actor Input (INPUT key-value record)
{
"startUrls": [{ "url": "https://example.com" }],
"maxDepth": 2,
"proxyConfiguration": { "useApifyProxy": true }
}
Datasets (append-only output)
import { Dataset } from 'apify';
await Dataset.pushData({ title: 'Hello', url: 'https://...' });
await Actor.pushData({ ... });
Key-Value Stores (arbitrary blobs)
await Actor.setValue('result', { items: [...] });
const val = await Actor.getValue('result');
await Actor.setValue('screenshot.png', buffer, { contentType: 'image/png' });
Request Queue (crawl frontier)
const queue = await Actor.openRequestQueue();
await queue.addRequest({ url: 'https://example.com' });
const req = await queue.fetchNextRequest();
await queue.markRequestHandled(req);
Advanced Patterns
Custom Playwright Scraper (Actor)
import { Actor } from 'apify';
import { PlaywrightCrawler } from 'crawlee';
await Actor.init();
const crawler = new PlaywrightCrawler({
launchContext: { launchOptions: { headless: true } },
async requestHandler({ page, request, enqueueLinks }) {
const data = await page.evaluate(() => ({
title: document.title,
url: location.href,
}));
await Actor.pushData(data);
await enqueueLinks();
},
});
await crawler.run([{ url: 'https://example.com' }]);
await Actor.exit();
Pagination
const crawler = new PlaywrightCrawler({
async requestHandler({ page, request, log }) {
const items = await page.locator('.item').allTextContents();
await Actor.pushData(items.map(text => ({ text, page: request.url })));
const next = await page.locator('a.next-page').getAttribute('href');
if (next) await crawler.addRequests([next]);
},
});
Proxy Rotation
const proxyConfiguration = await Actor.createProxyConfiguration({
groups: ['RESIDENTIAL'],
countryCode: 'US',
});
const crawler = new PlaywrightCrawler({ proxyConfiguration, ... });
Scheduling & Webhooks (cloud)
- Schedule an Actor via Apify Console → Actors → your actor → Schedules tab (cron syntax).
- Webhooks: Console → Actors → Webhooks — fire HTTP POST on
ACTOR.RUN.SUCCEEDED, ACTOR.RUN.FAILED, etc.
- CLI trigger:
apify call my-actor returns after the run completes; use --no-wait for fire-and-forget.
CSV/JSON Export
apify datasets get-items <id> > results.json
apify datasets get-items <id> --format=csv > results.csv
apify datasets get-items <id> | jq '[.[] | {title, price: .price | tonumber}]' > clean.json
duckdb -c "SELECT * FROM read_json_auto('results.json') LIMIT 10"
Apify Store (pre-built Actors)
apify call apify/web-scraper --input='{"startUrls":[{"url":"https://example.com"}]}'
Practical Examples
Scrape & Export in One Pipeline
apify run --purge
apify datasets get-items default --format=csv > output.csv
CI/CD Deployment
- run: |
npm install -g apify-cli
apify login --token ${{ secrets.APIFY_TOKEN }}
apify push --version-number=${{ github.run_number }}
Call Actor and Process Results
apify call my-actor --input=@input.json
DATASET_ID=$(apify actor --last-run-dataset-id)
apify datasets get-items "$DATASET_ID" | jq '.[] | select(.price < 100)'
Chaining with Other Skills
- Playwright (cli-playwright): Playwright is the recommended renderer inside Apify Actors; Apify provides the cloud infrastructure (proxy, scheduling, storage) while Playwright handles DOM interaction.
- jq: Pipe
apify datasets get-items output through jq to filter, reshape, or flatten nested scraping results before saving.
- DuckDB: Import exported JSON/CSV directly with
read_json_auto() / read_csv_auto() for SQL analytics on scraped data.