Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

node-crawler

> 开发工具
Open source

Web Crawler/Spider for NodeJS + server-side jQuery ;-)

6.8K stars0 likes0 views
WebsiteGitHub

About

Web Crawler/Spider for NodeJS + server-side jQuery ;-)


NPM download Package Quality

Crawler v2 : Advanced and Typescript version of node-crawler

Features:

  • Server-side DOM & automatic jQuery insertion with Cheerio (default),
  • Configurable pool size and retries,
  • Control rate limit,
  • Priority queue of requests,
  • let crawler deal for you with charset detection and conversion,

If you have prior experience with Crawler v1, for fast migration, please proceed to the section Differences and Breaking Changes.

Use with AI agents

This package ships an agent skill that teaches AI agents (e.g. OpenClaw, Hermes, Claude Code, Codex etc) how to crawl with crawler — queue vs. direct requests, rate limiting, proxy rotation, Cheerio parsing, and common pitfalls.

Recommended — install from ClawHub: clawhub.ai/mike442144/node-crawler

bash
openclaw skills install node-crawler

Fallback — download the skill bundle from the latest release and unzip it into your agent's skills directory:

bash
curl -L -o node-crawler-skill.zip https://github.com/bda-research/node-crawler/releases/latest/download/node-crawler-skill.zip
unzip node-crawler-skill.zip -d .openclaw/skills/

Let your agent install it — paste this prompt:

Install the node-crawler skill so you can use it for large-scale web crawling: download https://github.com/bda-research/node-crawler/releases/latest/download/node-crawler-skill.zip, unzip it, and place the node-crawler/ folder in your skills directory (e.g. .openclaw/skills/, .claude/skills/, or wherever your runtime loads skills from).

The agent loads it automatically when a task involves large-scale scraping or crawling.

Quick start

Install

Requires Node.js 22 or above.

bash
$ npm install crawler

Warning: Given the dependencies involved (Especially migrating from request to got) , Crawler v2 has been designed as a native ESM and no longer offers a CommonJS export. We would also like to recommend that you convert to ESM. Note that making this transition is generally not too difficult.If you have a large codebase built with Crawler v1, you can upgrade to v2.0.3-beta (using npm install crawler@beta), which supports both ESM and CommonJS builds.Please note that code previously using the "body" parameter to send form data in POST requests will need to be updated to use "form" even in the beta version.

Usage

Execute asynchronously via custom options

…

please refer to options for detail.

Slow down

Use rateLimit to slow down when you are visiting web sites.

javascript
import Crawler from "crawler";

const c = new Crawler({
    rateLimit: 1000, // `maxConnections` will be forced to 1
    callback: (err, res, done) => {
        console.log(res.$("title").text());
        done();
    },
});

c.add(tasks); //between two tasks, minimum time gap is 1000 (ms)

Custom parameters

Sometimes you have to access variables from previous request/response session, what should you do is passing parameters in options.userParams :

javascript
c.add({
    url: "http://www.google.com",
    userParams: {
        parameter1: "value1",
        parameter2: "value2",
        parameter3: "value3",
    },
});

then access them in callback via res.options

javascript
console.log(res.options.userParams);

Raw body

If you are downloading files like image, pdf, word etc, you have to save the raw response body which means Crawler shouldn't convert it to string. To make it happen, you need to set encoding to null

javascript
import Crawler from "crawler";
import fs from "fs";

const c = new Crawler({
    encoding: null,
    jQuery: false, // set false to suppress warning message.
    callback: (err, res, done) => {
        if (err) {
            console.error(err.stack);
        } else {
            fs.createWriteStream(res.options.userParams.filename).write(res.body);
        }
        done();
    },
});

c.add({
    url: "https://raw.githubusercontent.com/bda-research/node-crawler/master/crawler_primary.png",
    userParams: {
        filename: "crawler.png",
    },
});

preRequest

If you want to do something either synchronously or asynchronously before each request, you can try the code below. Note that direct requests won't trigger preRequest.

…

Direct request

Support both Promise and callback

…

Table

  • Content
    • Work with Http2
    • Work with rateLimiters
    • Class: Crawler
      • Event: 'schedule'
      • Event: 'limiterChange'
      • Event: 'request'
      • Event: 'drain'
      • crawler.add(url|options)
      • crawler.queueSize
    • Options
      • Global only options
        • silence
        • maxConnections
        • priorityLevels
        • rateLimit
        • skipDuplicates
        • homogeneous
        • userAgents
      • Crawler General options
        • url | method | headers | body | searchParams...
        • forceUTF8
        • jQuery
        • encoding
        • rateLimiterId
        • retries
        • retryInterval
        • timeout
        • priority
        • skipEventRequest
        • html
        • proxies
        • proxy
        • http2
        • autoSelectFamily
        • autoSelectFamilyAttemptTimeout
        • referer
        • userParams
        • preRequest
        • Callback
    • Work with Cheerio
  • Differences and Breaking Changes
    • renaming
      • Crawler Options
      • Origin Request Options
    • Behavior Changes
  • How to test

Content

Work with Http2

Now we offer hassle-free support for using HTTP/2: just set http2 to true, and Crawler will operate as smoothly as with HTTP (including proxies).

Note: As most developers using this library with proxies also work with Charles, it is expected to set rejectAuthority to false in order to prevent the so-called 'self-signed certificate' errors."

javascript
crawler.send({
    url: "https://nghttp2.org/httpbin/status/200",
    method: "GET",
    http2: true,
    callback: (error, response) => {
        if (error) {
            console.error(error);
        }
        console.log(`inside callback`);
        console.log(response.body);
    },
});

Work with rateLimiters

Control the rate limit. All tasks submit to a rateLimiter will abide the rateLimit and maxConnections restrictions of the limiter. rateLimit is the minimum time gap between two tasks. maxConnections is the maximum number of tasks that can be running at the same time. rateLimiters are independent of each other. One common use case is setting different rateLimiters for different proxies. One thing is worth noticing, when rateLimit is set to a non-zero value, maxConnections will be forced to 1.

…

Normally, all ratelimiters instances in the limiter cluster of crawler are instantiated with options specified in crawler constructor. You can change property of any rateLimiter by calling the code below. Currently, we only support changing property 'rateLimit' of it. Note that the default rateLimiter can be accessed by crawler.setLimiter(0, "rateLimit", 1000);. We strongly recommend that you leave limiters unchanged after their instantiation unless you know clearly what you are doing.

javascript
const crawler = new Crawler();
crawler.setLimiter(0, "rateLimit", 1000);

Class: Crawler

Event: 'schedule'

  • options

Emitted when a task is being added to scheduler.

javascript
crawler.on("schedule", options => {
    options.proxy = "http://proxy:port";
});

Event: 'limiterChange'

  • options
  • rateLimiterId : number

Emitted when limiter has been changed.

Event: 'request'

  • options

Emitted when crawler is ready to send a request.

If you are going to modify options at last stage before requesting, just listen on it.

javascript
crawler.on("request", options => {
    options.searchParams.timestamp = new Date().getTime();
});

Event: 'drain'

Emitted when queue is empty.

javascript
crawler.on("drain", () => {
    // For example, release a connection to database.
    db.end(); // close connection to MySQL
});

crawler.add(url|options)

  • url | options

Add a task to queue and wait for it to be executed.

crawler.queueSize

  • Number

Size of queue, read-only

Options

You can pass these options to the Crawler() constructor if you want them to be global or as items in the crawler.add() calls if you want them to be specific to that item (overwriting global options)

  • For using easily, simply passing a url string as Options is also accepted.
  • Options can also be an array composed of multiple options, in which case multiple tasks will be added at once.
  • When constructing options, all native got options are accepted and passed through directly. Additionally, the options are tailored to process only those parameters that are identifiable by the Crawler.

Global only options

silence

  • Type: boolean
  • Default : false
  • If true, the crawler will mute all warning and error messages. The request error will be still reported.

maxConnections

  • Type: number
  • Default : 10
  • The maximum number of requests that can be sent simultaneously. If the value is 10, the crawler will send at most 10 requests at the same time.

priorityLevels

  • Type: number
  • Default : 10
  • The number of levels of priority. Can be only assigned at the beginning.

rateLimit

  • Type: number

  • Default : 0

  • 1000 means 1000 milliseconds delay between after the first request.

  • Note: This options is list as global only options because it will be set as the "default rateLimit value". This value is bound to a specific rate limiter and can only be modified through the crawler.setLimiter method. Please avoid passing redundant rateLimit property in local requests; instead, use options.rateLimiterId to specify a particular limiter.

  • Example:

    javascript
    crawler.on("schedule", options => {
        options.rateLimiterId = Math.floor(Math.random() * 15);
    });

skipDuplicates

  • Type: boolean
  • Default : false
  • If true, the crawler will skip duplicate tasks. If the task is already in the queue, the crawler will not add it again.

homogeneous

  • *Type:

Issues· 29 open

View all issuesOpen on GitHub
  • #483

    RequestError: The "msecs" argument must be of type number. Received undefined. When used with socks-proxy-agent.

    Updated Jun 14, 2026
  • #465

    cannot get section node

    Updated Apr 29, 2024
  • #370

    Returning data from callback

    Updated Aug 24, 2022
  • #380

    Abort crawling

    Updated Nov 26, 2021
  • #377

    Inconsistent variable names across examples

    Updated Nov 8, 2021
  • #371

    Some requests (stream based) never ends and block the queue

    Updated Mar 5, 2021
  • #339

    Uncatchable error

    Updated Dec 9, 2020
  • #366

    jsdom.env is not defined

    Updated Nov 20, 2020
  • #365

    Documentation unclear; CRAWLER Error Error: incorrect header check when fetching

    Updated Oct 26, 2020
  • #358

    Add support for use a list of proxy

    Updated Oct 15, 2020

> Tags

TypeScriptcheeriocrawlerextract-datajavascript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 23, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具