crawlee README

The project's README from github.com/apify/crawlee. As one markdown file: README.md.

Crawlee
A web scraping and browser automation library

apify%2Fcrawlee | Trendshift

NPM latest version Downloads Chat on discord Build Status

Crawlee covers your crawling and scraping end-to-end and helps you build reliable scrapers. Fast.

Your crawlers will appear human-like and fly under the radar of modern bot protections even with the default configuration. Crawlee gives you the tools to crawl the web for links, scrape data, and store it to disk or cloud while staying configurable to suit your project's needs.

Crawlee is available as the crawlee NPM package.

👉 View full documentation, guides and examples on the Crawlee project website 👈

Do you prefer 🐍 Python instead of JavaScript? 👉 Checkout Crawlee for Python 👈.

Installation

We recommend visiting the Introduction tutorial in Crawlee documentation for more information.

Crawlee requires Node.js 16 or higher.

With Crawlee CLI

The fastest way to try Crawlee out is to use the Crawlee CLI and choose the Getting started example. The CLI will install all the necessary dependencies and add boilerplate code for you to play with.

npx crawlee create my-crawler
cd my-crawler
npm start

Manual installation

If you prefer adding Crawlee into your own project, try the example below. Because it uses PlaywrightCrawler we also need to install Playwright. It's not bundled with Crawlee to reduce install size.

npm install crawlee playwright
import { PlaywrightCrawler, Dataset } from 'crawlee';

// PlaywrightCrawler crawls the web using a headless
// browser controlled by the Playwright library.
const crawler = new PlaywrightCrawler({
    // Use the requestHandler to process each of the crawled pages.
    async requestHandler({ request, page, enqueueLinks, log }) {
        const title = await page.title();
        log.info(`Title of ${request.loadedUrl} is '${title}'`);

        // Save results as JSON to ./storage/datasets/default
        await Dataset.pushData({ title, url: request.loadedUrl });

        // Extract links from the current page
        // and add them to the crawling queue.
        await enqueueLinks();
    },
    // Uncomment this option to see the browser window.
    // headless: false,
});

// Add first URL to the queue and start the crawl.
await crawler.run(['https://crawlee.dev']);

By default, Crawlee stores data to ./storage in the current working directory. You can override this directory via Crawlee configuration. For details, see Configuration guide, Request storage and Result storage.

Installing pre-release versions

We provide automated beta builds for every merged code change in Crawlee. You can find them in the npm list of releases. If you want to test new features or bug fixes before we release them, feel free to install a beta build like this:

npm install crawlee@next

If you also use the Apify SDK, you need to specify dependency overrides in your package.json file so that you don't end up with multiple versions of Crawlee installed:

{
    "overrides": {
       "apify": {
           "@crawlee/core": "$crawlee",
           "@crawlee/types": "$crawlee",
           "@crawlee/utils": "$crawlee"
       }
    }
}

🛠 Features

👾 HTTP crawling

💻 Real browser crawling

Usage on the Apify platform

Crawlee is open-source and runs anywhere, but since it's developed by Apify, it's easy to set up on the Apify platform and run in the cloud. Visit the Apify SDK website to learn more about deploying Crawlee to the Apify platform.

Support

If you find any bug or issue with Crawlee, please submit an issue on GitHub. For questions, you can ask on Stack Overflow, in GitHub Discussions or you can join our Discord server.

Contributing

Your code contributions are welcome, and you'll be praised to eternity! If you have any ideas for improvements, either submit an issue or create a pull request. For contribution guidelines and the code of conduct, see CONTRIBUTING.md.

License

This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details.

crawlee (apify/crawlee)

Searching Database…

26.2K ·GitHub
这是什么?一个面向 Node.js 的网页抓取和浏览器自动化库:你用 JavaScript 或 TypeScript 编写爬虫,去抓取网站、提取数据(比如用于 AI、LLM 和 RAG 流程),并把数据保存到本地磁盘或云端。
这是一个写代码用的库,还是现成的抓取软件?是一个库,不是软件:你安装 crawlee 这个 npm 包,然后自己用 JS/TS 写爬虫。自带的 CLI 只是帮你生成一个起始项目而已。
我该怎么用它搭建第一个爬虫?最快的办法:运行 Crawlee CLI 并选择 Getting started 示例——它会装好依赖并生成可以动手玩的模板代码。或者把 crawlee 包添加到你自己的 Node.js 项目里。
它自带浏览器吗,还是我得自己装?要做浏览器抓取的话,Playwright 或 Puppeteer 得自己装——Crawlee 特意不打包它们,好让安装包更小。除此之外你只需要 Node.js 16 或更高版本。
有反爬虫防护的网站会挡住我的爬虫吗?对抗封锁正是它的强项:即使全用默认设置,抓取行为看起来也像真人,能绕过现代的机器人防护——代理轮换、会话管理和接近浏览器的 TLS 指纹都是内置的。
它必须跑在 Apify 云上吗?不用——它是开源的,只要能跑 Node.js 的地方都能运行,从你自己的笔记本到你自己的服务器都行。Apify 平台只是同一个团队提供的可选托管服务。
抓下来的数据存在哪里?默认保存在你工作目录下的 ./storage 文件夹里;你可以在配置中修改这个路径,表格数据和文件这两类存储也都是可插拔的。
除了 HTML 页面,它还能抓什么?JSON API 也没问题,还能下载 PDF、图片之类的文件;在浏览器模式下,它能渲染重度依赖 JavaScript 的页面,还可以截图。
它支持哪些浏览器和驱动?在统一接口背后支持 Playwright 和 Puppeteer,可以无头或有头模式驱动 Chrome、Firefox、WebKit 等浏览器,并自动管理浏览器的启动和关闭。
Creator
apify
Size
172.7 MB
Stars
26.2K
Age
10y
Commits · 90 Days