Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

638 B
Raw Blame
import { CheerioCrawler, Statistics } from 'crawlee';

// Declare the extra fields and their initial values. Their types flow into `statistics.state`.
const statistics = new Statistics({
    stateExtension: { defaultState: { productsFound: 0 } },
});

const crawler = new CheerioCrawler({
    statistics,
    async requestHandler({ $, enqueueLinks }) {
        statistics.state.productsFound += $('.product').length;

        await enqueueLinks();
    },
});

await crawler.run(['https://crawlee.dev']);

// The custom fields are typed on `crawler.statistics` too.
console.log(`Found ${crawler.statistics.state.productsFound} products`);