Back to Crawlee

Setting up

website/versioned_docs/version-3.16/introduction/01-setting-up.mdx

3.16.03.2 KB
Original Source

import ThemedImage from '@theme/ThemedImage';

import ApiLink from '@site/src/components/ApiLink';

To run Crawlee on your own computer, you need to meet the following pre-requisites first:

  1. Have Node.js version 16.0 (Visit Node.js website to download or use fnm) or higher installed.
  2. Have NPM installed, or use other package manager of your choice.

If not certain, confirm the prerequisites by running:

bash
node -v
bash
npm -v

Creating a new project

The fastest and best way to create new projects with Crawlee is to use the Crawlee CLI. You can use the npx utility to download and run the CLI - it is embedded in the crawlee package:

bash
npx crawlee create my-crawler

A prompt will be shown, asking you to select a template. Crawlee is written in TypeScript so if you're familiar with it, choosing a TypeScript template will give you better code completion and static type checking, but feel free to use JavaScript as well. Functionally they're identical.

Let's choose the first template called Getting started example. The command will create a new directory in your current working directory, called my-crawler, add a package.json to this folder and install all the necessary dependencies. It will also add example source code that you can immediately run.

Let's try that!

bash
cd my-crawler
npm start

You will see log messages in the terminal as Crawlee boots up and starts scraping the Crawlee website.

log
INFO  PlaywrightCrawler: Starting the crawl
INFO  PlaywrightCrawler: Title of https://crawlee.dev/ is 'Crawlee · Build reliable crawlers. Fast. | Crawlee'
INFO  PlaywrightCrawler: Title of https://crawlee.dev/js/docs/examples is 'Examples | Crawlee'
INFO  PlaywrightCrawler: Title of https://crawlee.dev/js/api/core is '@crawlee/core | API | Crawlee'
INFO  PlaywrightCrawler: Title of https://crawlee.dev/js/api/core/changelog is 'Changelog | API | Crawlee'
INFO  PlaywrightCrawler: Title of https://crawlee.dev/js/docs/quick-start is 'Quick Start | Crawlee'

You can always terminate the crawl with a keypress in the terminal:

text
CTRL+C

Running headful browsers

Browsers controlled by Playwright run headless (without a visible window). You can switch to headful by uncommenting the headless: false option in the crawler's constructor. This is useful in the development phase when you want to see what's going on in the browser.

typescript
// Uncomment this option to see the browser window.
headless: false

When you run the example again, after a second a Chromium browser window will open. In the window, you'll see quickly changing pages as the crawler does its job.

:::note

For the sake of this show off, we've slowed down the crawler, but rest assured, it's blazing fast in real world usage.

:::

<ThemedImage alt="An image showing off Crawlee scraping the Crawlee website using Puppeteer/Playwright and Chromium" sources={{ light: '/img/chrome-scrape-light.gif', dark: '/img/chrome-scrape-dark.gif', }} />

Next steps

Next, you will see how to create a very simple crawler and explain Crawlee components while building it.