JavaScript Cheerio crawler
A fast HTTP crawler that extracts data from every page. Good for simple sites like blogs, news, or product listings, but it can't run client-side JavaScript.
src/main.js
1// Crawlee - web scraping and browser automation library (Read more at https://crawlee.dev)2import { CheerioCrawler } from '@crawlee/cheerio';3// Apify SDK - toolkit for building Apify Actors (Read more at https://docs.apify.com/sdk/js/)4import { Actor } from 'apify';5
6// this is ESM project, and as such, it requires you to specify extensions in your relative imports7// read more about this here: https://nodejs.org/docs/latest-v18.x/api/esm.html#mandatory-file-extensions8import { router } from './routes.js';9
10// The init() call configures the Actor to correctly work with the Apify-provided environment - mainly the storage infrastructure. It is necessary that every Actor performs an init() call.11await Actor.init();12
13// Structure of input is defined in input_schema.json14const { startUrls = ['https://apify.com'], maxRequestsPerCrawl = 100 } = (await Actor.getInput()) ?? {};15
16// Proxy configuration to rotate IP addresses and prevent blocking (https://docs.apify.com/platform/proxy)17// `checkAccess` flag ensures the proxy credentials are valid, but the check can take a few hundred milliseconds.18// Disable it for short runs if you are sure your proxy configuration is correct19const proxyConfiguration = await Actor.createProxyConfiguration({ checkAccess: true });20
21const crawler = new CheerioCrawler({22 proxyConfiguration,23 maxRequestsPerCrawl,24 requestHandler: router,25});26
27await crawler.run(startUrls);28
29// Gracefully exit the Actor process. It's recommended to quit all Actors with an exit()30await Actor.exit();This template example was built with Crawlee to scrape data from a website using Cheerio wrapped into CheerioCrawler .
Once you've installed the dependencies, start the Actor:
$apify run
Once your Actor is ready, you can push it to the Apify Console:
apify login # first, you need to log in if you haven't already done soapify push
.actor/├── actor.json # Actor config: name, version, env vars, runtime settings├── dataset_schema.json # Structure and representation of data produced by an Actor├── input_schema.json # Input validation & Console form definition└── output_schema.json # Specifies where an Actor stores its outputsrc/└── main.js # Actor entry point and orchestratorstorage/ # Local storage (mirrors Cloud during development)├── datasets/ # Output items (JSON objects)├── key_value_stores/ # Files, config, INPUT└── request_queues/ # Pending crawl requestsDockerfile # Container image definition
For more information, see the Actor definition documentation.
This code is a JavaScript script that uses Cheerio to scrape data from a website. It then stores the website titles in a dataset.
- The crawler starts with URLs provided from the input
startUrlsfield defined by the input schema. Number of scraped pages is limited bymaxPagesPerCrawlfield from the input schema. - The crawler uses
requestHandlerfor each URL to extract the data from the page with the Cheerio library and to save the title and URL of each page to the dataset. It also logs out each result that is being saved.
- Apify SDK - toolkit for building Actors
- Crawlee - web scraping and browser automation library
- Input schema - define and easily validate a schema for your Actor's input
- Dataset - store structured data where each object stored has the same attributes
- Cheerio - a fast, flexible & elegant library for parsing and manipulating HTML and XML
- Proxy configuration - rotate IP addresses to prevent blocking
- Quick Start guide for building your first Actor
- Video tutorial on building a scraper using CheerioCrawler
- Written tutorial on building a scraper using CheerioCrawler
- Web scraping with Cheerio in 2023
- How to scrape a dynamic page using Cheerio
- Integration with Zapier , Make, Google Drive and others
- Video guide on getting data using Apify API
JavaScript one-page scraper
Get data from one web page with Cheerio. The simplest way to start scraping.
JavaScript Puppeteer scraper
A headless Chrome scraper that renders JavaScript before extracting data. Good for social feeds, dashboards, or single-page apps.
JavaScript Playwright scraper
A Playwright-based browser scraper supporting multiple browsers and contexts.
JavaScript Camoufox scraper
A Firefox-based browser built to look like a real user and bypass bot protection.
Cheerio crawler (advanced)
A minimal crawler for developers who already know the Apify SDK and Crawlee.
Cypress test runner
A cloud test runner for Cypress that saves results and videos.