@crawlee/templates 3.0.4-beta.6 → 3.0.4-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +68 -99
  2. package/manifest.json +14 -6
  3. package/package.json +1 -1
  4. package/templates/cheerio-js/.dockerignore +10 -0
  5. package/templates/cheerio-js/Dockerfile +20 -6
  6. package/templates/cheerio-js/package.json +0 -1
  7. package/templates/cheerio-js/src/routes.js +9 -9
  8. package/templates/cheerio-ts/.dockerignore +10 -0
  9. package/templates/cheerio-ts/Dockerfile +32 -14
  10. package/templates/cheerio-ts/src/routes.ts +10 -10
  11. package/templates/getting-started-js/.dockerignore +10 -0
  12. package/templates/getting-started-js/Dockerfile +29 -0
  13. package/templates/getting-started-js/README.md +9 -0
  14. package/templates/getting-started-js/package.json +16 -0
  15. package/templates/getting-started-js/src/main.js +24 -0
  16. package/templates/getting-started-ts/.dockerignore +10 -0
  17. package/templates/getting-started-ts/Dockerfile +51 -0
  18. package/templates/getting-started-ts/README.md +9 -0
  19. package/templates/getting-started-ts/package.json +24 -0
  20. package/templates/getting-started-ts/src/main.ts +24 -0
  21. package/templates/getting-started-ts/tsconfig.json +13 -0
  22. package/templates/playwright-js/.dockerignore +10 -0
  23. package/templates/playwright-js/Dockerfile +20 -6
  24. package/templates/playwright-js/README.md +0 -18
  25. package/templates/playwright-js/package.json +0 -1
  26. package/templates/playwright-js/src/routes.js +9 -9
  27. package/templates/playwright-ts/.dockerignore +10 -0
  28. package/templates/playwright-ts/Dockerfile +35 -16
  29. package/templates/playwright-ts/README.md +0 -18
  30. package/templates/playwright-ts/src/routes.ts +9 -9
  31. package/templates/puppeteer-js/.dockerignore +10 -0
  32. package/templates/puppeteer-js/Dockerfile +20 -6
  33. package/templates/puppeteer-js/README.md +0 -18
  34. package/templates/puppeteer-js/package.json +0 -1
  35. package/templates/puppeteer-js/src/routes.js +9 -9
  36. package/templates/puppeteer-ts/.dockerignore +10 -0
  37. package/templates/puppeteer-ts/Dockerfile +35 -16
  38. package/templates/puppeteer-ts/README.md +0 -18
  39. package/templates/puppeteer-ts/src/routes.ts +9 -9
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  </picture>
7
7
  </a>
8
8
  <br>
9
- <small>The scalable web crawling and scraping library for JavaScript</small>
9
+ <small>The web scraping and browser automation library</small>
10
10
  </h1>
11
11
 
12
12
  <p align=center>
@@ -16,138 +16,107 @@
16
16
  <a href="https://github.com/apify/crawlee/actions/workflows/test-and-release.yml"><img src="https://github.com/apify/crawlee/actions/workflows/test-and-release.yml/badge.svg?branch=master" alt="Build Status" style="max-width: 100%;"></a>
17
17
  </p>
18
18
 
19
- >👉👉👉 Crawlee is the successor to [Apify SDK](https://sdk.apify.com). 🎉 Fully rewritten in **TypeScript** for a better developer experience, and with even more powerful anti-blocking features. The interface is almost the same as Apify SDK so upgrading is a breeze. Read [the upgrading guide](https://crawlee.dev/docs/upgrading/upgrading-to-v3) to learn about the changes. 👈👈👈
19
+ > â„šī¸ Crawlee is the successor to [Apify SDK](https://sdk.apify.com). 🎉 Fully rewritten in **TypeScript** for a better developer experience, and with even more powerful anti-blocking features. The interface is almost the same as Apify SDK so upgrading is a breeze. Read [the upgrading guide](https://crawlee.dev/docs/upgrading/upgrading-to-v3) to learn about the changes. â„šī¸
20
20
 
21
- Crawlee simplifies the development of web crawlers, scrapers, data extractors and web automation jobs. It provides tools to manage and automatically scale a pool of headless browsers, to maintain queues of URLs to crawl, store crawling results to a local filesystem or into the cloud, rotate proxies and much more. Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) NPM package. It can be used either stand-alone in your own applications or in [actors](https://docs.apify.com/actor) running on the [Apify Cloud](https://apify.com/).
21
+ Crawlee covers your crawling and scraping end-to-end and **helps you build reliable scrapers. Fast.**
22
22
 
23
- **View full documentation, guides and examples on the [Crawlee project website](https://crawlee.dev)**
23
+ 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.
24
24
 
25
- > Would you like to work with us on Crawlee or similar projects? [We are hiring!](https://apify.com/jobs#senior-node.js-engineer)
25
+ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) NPM package.
26
26
 
27
- ## Motivation
27
+ > 👉 **View full documentation, guides and examples on the [Crawlee project website](https://crawlee.dev)** 👈
28
28
 
29
- Thanks to tools like [Playwright](https://github.com/microsoft/playwright), [Puppeteer](https://github.com/puppeteer/puppeteer) or [Cheerio](https://www.npmjs.com/package/cheerio), it is easy to write Node.js code to extract data from web pages. But eventually things will get complicated. For example, when you try to:
29
+ ## Installation
30
30
 
31
- - Perform a deep crawl of an entire website using a persistent queue of URLs.
32
- - Run your scraping code on a list of 100k URLs in a CSV file, without losing any data when your code crashes.
33
- - Rotate proxies to hide your browser origin and keep user-like sessions.
34
- - Disable browser fingerprinting protections used by websites.
31
+ We recommend visiting the [Introduction tutorial](https://crawlee.dev/docs/introduction) in Crawlee documentation for more information.
35
32
 
36
- Python has [Scrapy](https://scrapy.org/) for these tasks, but there was no such library for **JavaScript, the language of the web**. The use of JavaScript is natural, since the same language is used to write the scripts as well as the data extraction code running in a browser.
33
+ > Crawlee requires **Node.js 16 or higher**.
37
34
 
38
- The goal of Crawlee is to fill this gap and provide a toolbox for generic web scraping, crawling and automation tasks in JavaScript. So don't reinvent the wheel every time you need data from the web, and focus on writing code specific to the target website, rather than developing commonalities.
35
+ ### With Crawlee CLI
39
36
 
40
- ## Overview
37
+ 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.
41
38
 
42
- Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) NPM package and is also available via `@crawlee/*` packages. It provides the following tools:
43
-
44
- - [`CheerioCrawler`](https://crawlee.dev/api/cheerio-crawler/class/CheerioCrawler) - Enables the parallel crawling of a large number of web pages using the [cheerio](https://www.npmjs.com/package/cheerio) HTML parser. This is the most efficient web crawler, but it does not work on websites that require JavaScript. Available also under `@crawlee/cheerio` package.
45
-
46
- - [`PuppeteerCrawler`](https://crawlee.dev/api/puppeteer-crawler/class/PuppeteerCrawler) - Enables the parallel crawling of a large number of web pages using the headless Chrome browser and [Puppeteer](https://github.com/puppeteer/puppeteer). The pool of Chrome browsers is automatically scaled up and down based on available system resources. Available also under `@crawlee/puppeteer` package.
47
-
48
- - [`PlaywrightCrawler`](https://crawlee.dev/api/playwright-crawler/class/PlaywrightCrawler) - Unlike `PuppeteerCrawler` you can use [Playwright](https://github.com/microsoft/playwright) to manage almost any headless browser. It also provides a cleaner and more mature interface while keeping the ease of use and advanced features. Available also under `@crawlee/playwright` package.
49
-
50
- - [`BasicCrawler`](https://crawlee.dev/api/basic-crawler/class/BasicCrawler) - Provides a simple framework for the parallel crawling of web pages whose URLs are fed either from a static list or from a dynamic queue of URLs. This class serves as a base for the more specialized crawlers above. Available also under `@crawlee/basic` package.
51
-
52
- - [`RequestList`](https://crawlee.dev/api/core/class/RequestList) - Represents a list of URLs to crawl. The URLs can be passed in code or in a text file hosted on the web. The list persists its state so that crawling can resume when the Node.js process restarts. Available also under `@crawlee/core` package.
53
-
54
- - [`RequestQueue`](https://crawlee.dev/api/core/class/RequestQueue) - Represents a queue of URLs to crawl, which is stored either in memory, on a local filesystem, or in the [Apify Cloud](https://apify.com). The queue is used for deep crawling of websites, where you start with several URLs and then recursively follow links to other pages. The data structure supports both breadth-first and depth-first crawling orders. Available also under `@crawlee/core` package.
55
-
56
- - [`Dataset`](https://crawlee.dev/api/core/class/Dataset) - Provides a store for structured data and enables their export to formats like JSON, JSONL, CSV, XML, Excel or HTML. The data is stored on a local filesystem or in the Apify Cloud. Datasets are useful for storing and sharing large tabular crawling results, such as a list of products or real estate offers. Available also under `@crawlee/core` package.
57
-
58
- - [`KeyValueStore`](https://crawlee.dev/api/core/class/KeyValueStore) - A simple key-value store for arbitrary data records or files, along with their MIME content type. It is ideal for saving screenshots of web pages, PDFs or to persist the state of your crawlers. The data is stored on a local filesystem or in the Apify Cloud. Available also under `@crawlee/core` package.
59
-
60
- - [`AutoscaledPool`](https://crawlee.dev/api/core/class/AutoscaledPool) - Runs asynchronous background tasks, while automatically adjusting the concurrency based on free system memory and CPU usage. This is useful for running web scraping tasks at the maximum capacity of the system. Available also under `@crawlee/core` package.
61
-
62
- Additionally, the package provides various helper functions to simplify running your code on the Apify Cloud and thus take advantage of its pool of proxies, job scheduler, data storage, etc. For more information, see the [Crawlee Programmer's Reference](https://crawlee.dev).
63
-
64
- ## Quick Start
65
-
66
- This short tutorial will set you up to start using Crawlee in a minute or two. If you want to learn more, proceed to the [Getting Started](https://crawlee.dev/docs/introduction) tutorial that will take you step by step through creating your first scraper.
39
+ ```bash
40
+ npx crawlee create my-crawler
41
+ ```
67
42
 
68
- ### Local stand-alone usage
43
+ ```bash
44
+ cd my-crawler
45
+ npm start
46
+ ```
69
47
 
70
- Crawlee requires [Node.js](https://nodejs.org/en/) 16 or later. Add Crawlee to any Node.js project by running:
48
+ ### Manual installation
49
+ If you prefer adding Crawlee **into your own project**, try the example below. Because it uses `PlaywrightCrawler` we also need to install [Playwright](https://playwright.dev). It's not bundled with Crawlee to reduce install size.
71
50
 
72
51
  ```bash
73
52
  npm install crawlee playwright
74
53
  ```
75
54
 
76
- > Neither `playwright` nor `puppeteer` are bundled with Crawlee to reduce install size and allow greater flexibility. That's why we install it with NPM. You can choose one, both, or neither.
77
-
78
- Run the following example to perform a recursive crawl of a website using Playwright. For more examples showcasing various features of Crawlee, [see the Examples section of the documentation](https://crawlee.dev/docs/examples/crawl-multiple-urls).
79
-
80
- ```javascript
55
+ ```js
81
56
  import { PlaywrightCrawler, Dataset } from 'crawlee';
82
57
 
83
- const crawler = new PlaywrightCrawler();
84
-
85
- crawler.router.addDefaultHandler(async ({ request, page, enqueueLinks }) => {
86
- const title = await page.title();
87
- console.log(`Title of ${request.loadedUrl} is '${title}'`);
88
-
89
- // save some results
90
- await Dataset.pushData({ title, url: request.loadedUrl });
91
-
92
- // enqueue all links targeting the same hostname
93
- await enqueueLinks();
58
+ // PlaywrightCrawler crawls the web using a headless
59
+ // browser controlled by the Playwright library.
60
+ const crawler = new PlaywrightCrawler({
61
+ // Use the requestHandler to process each of the crawled pages.
62
+ async requestHandler({ request, page, enqueueLinks, log }) {
63
+ const title = await page.title();
64
+ log.info(`Title of ${request.loadedUrl} is '${title}'`);
65
+
66
+ // Save results as JSON to ./storage/datasets/default
67
+ await Dataset.pushData({ title, url: request.loadedUrl });
68
+
69
+ // Extract links from the current page
70
+ // and add them to the crawling queue.
71
+ await enqueueLinks();
72
+ },
73
+ // Uncomment this option to see the browser window.
74
+ // headless: false,
94
75
  });
95
76
 
96
- await crawler.run(['https://www.iana.org/']);
77
+ // Add first URL to the queue and start the crawl.
78
+ await crawler.run(['https://crawlee.dev']);
97
79
  ```
98
80
 
99
- When you run the example, you should see Crawlee automating a Chrome browser.
100
-
101
- ![Chrome Scrape](https://crawlee.dev/img/chrome_scrape.gif)
102
-
103
- By default, Crawlee stores data to `./storage` in the current working directory. You can override this directory via `CRAWLEE_STORAGE_DIR` env var. For details, see [Environment variables](https://crawlee.dev/docs/guides/environment-variables), [Request storage](https://crawlee.dev/docs/guides/request-storage) and [Result storage](https://crawlee.dev/docs/guides/result-storage).
104
-
105
- ### Local usage with Crawlee command-line interface (CLI)
106
-
107
- To create a boilerplate of your project we can use the [Crawlee command-line interface (CLI)](https://github.com/apify/apify-cli) tool.
81
+ 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](https://crawlee.dev/docs/guides/configuration), [Request storage](https://crawlee.dev/docs/guides/request-storage) and [Result storage](https://crawlee.dev/docs/guides/result-storage).
108
82
 
109
- Let's create a boilerplate of your new web crawling project by running:
83
+ ## 🛠 Features
110
84
 
111
- ```bash
112
- npx crawlee create my-hello-world
113
- ```
114
-
115
- The CLI will prompt you to select a project boilerplate template - just pick "Hello world". The tool will create a directory called `my-hello-world` with a Node.js project files. You can run the project as follows:
85
+ - Single interface for **HTTP and headless browser** crawling
86
+ - Persistent **queue** for URLs to crawl (breadth & depth first)
87
+ - Pluggable **storage** of both tabular data and files
88
+ - Automatic **scaling** with available system resources
89
+ - Integrated **proxy rotation** and session management
90
+ - Lifecycles customizable with **hooks**
91
+ - **CLI** to bootstrap your projects
92
+ - Configurable **routing**, **error handling** and **retries**
93
+ - **Dockerfiles** ready to deploy
94
+ - Written in **TypeScript** with generics
116
95
 
117
- ```bash
118
- cd my-hello-world
119
- npx crawlee run
120
- ```
96
+ ### 👾 HTTP crawling
121
97
 
122
- By default, the crawling data will be stored in a local directory at `./storage`. For example, the input JSON file for the actor is expected to be in the default key-value store in `./storage/key_value_stores/default/INPUT.json`.
98
+ - Zero config **HTTP2 support**, even for proxies
99
+ - Automatic generation of **browser-like headers**
100
+ - Replication of browser **TLS fingerprints**
101
+ - Integrated fast **HTML parsers**. Cheerio and JSDOM
102
+ - Yes, you can scrape **JSON APIs** as well
123
103
 
124
- ### Usage on the Apify platform
125
-
126
- Now if we want to run our new crawler on Apify Platform, we first need to download the `apify-cli` and login with our token:
127
-
128
- > We could also use the Apify CLI to generate a new project, which can be better suited if we want to run it on the Apify Platform.
129
-
130
- ```bash
131
- npm i -g apify-cli
132
- apify login
133
- ```
134
-
135
- Finally, we can easily deploy our code to the Apify platform by running:
136
-
137
- ```bash
138
- apify push
139
- ```
104
+ ### đŸ’ģ Real browser crawling
140
105
 
141
- Your script will be uploaded to the Apify platform and built there so that it can be run. For more information, view the
142
- [Apify Actor](https://docs.apify.com/cli) documentation.
106
+ - JavaScript **rendering** and **screenshots**
107
+ - **Headless** and **headful** support
108
+ - Zero-config generation of **human-like fingerprints**
109
+ - Automatic **browser management**
110
+ - Use **Playwright** and **Puppeteer** with the same interface
111
+ - **Chrome**, **Firefox**, **Webkit** and many others
143
112
 
144
- You can also develop your web scraping project in an online code editor directly on the [Apify platform](https://crawlee.dev/docs/guides/apify-platform). You'll need to have an Apify Account. Go to [Actors](https://console.apify.com/actors), page in the Apify Console, click <i>Create new</i> and then go to the <i>Source</i> tab and start writing your code or paste one of the examples from the Examples section.
113
+ ## Usage on the Apify platform
145
114
 
146
- For more information, view the [Apify actors quick start guide](https://docs.apify.com/actor/quick-start).
115
+ Crawlee is open-source and runs anywhere, but since it's developed by [Apify](https://apify.com), it's easy to set up on the Apify platform and run in the cloud. Visit the [Apify SDK website](https://sdk.apify.com) to learn more about deploying Crawlee to the Apify platform.
147
116
 
148
117
  ## Support
149
118
 
150
- If you find any bug or issue with Crawlee, please [submit an issue on GitHub](https://github.com/apify/crawlee/issues). For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify) or contact support@apify.com
119
+ If you find any bug or issue with Crawlee, please [submit an issue on GitHub](https://github.com/apify/crawlee/issues). For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify), in GitHub Discussions or you can join our [Discord server](https://discord.com/invite/jyEM2PRvMU).
151
120
 
152
121
  ## Contributing
153
122
 
package/manifest.json CHANGED
@@ -1,28 +1,36 @@
1
1
  {
2
2
  "templates": [
3
+ {
4
+ "name": "getting-started-ts",
5
+ "description": "Getting started example [TypeScript]"
6
+ },
7
+ {
8
+ "name": "getting-started-js",
9
+ "description": "Getting started example [JavaScript]"
10
+ },
3
11
  {
4
12
  "name": "cheerio-ts",
5
- "description": "Crawlee cheerio template [TypeScript]"
13
+ "description": "CheerioCrawler template project [TypeScript]"
6
14
  },
7
15
  {
8
16
  "name": "playwright-ts",
9
- "description": "Crawlee playwright template [TypeScript]"
17
+ "description": "PlaywrightCrawler template project [TypeScript]"
10
18
  },
11
19
  {
12
20
  "name": "puppeteer-ts",
13
- "description": "Crawlee puppeteer template [TypeScript]"
21
+ "description": "PuppeteerCrawler template project [TypeScript]"
14
22
  },
15
23
  {
16
24
  "name": "cheerio-js",
17
- "description": "Crawlee cheerio template [JavaScript]"
25
+ "description": "CheerioCrawler template project [JavaScript]"
18
26
  },
19
27
  {
20
28
  "name": "playwright-js",
21
- "description": "Crawlee playwright template [JavaScript]"
29
+ "description": "PlaywrightCrawler template project [JavaScript]"
22
30
  },
23
31
  {
24
32
  "name": "puppeteer-js",
25
- "description": "Crawlee puppeteer template [JavaScript]"
33
+ "description": "PuppeteerCrawler template project [JavaScript]"
26
34
  }
27
35
  ]
28
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/templates",
3
- "version": "3.0.4-beta.6",
3
+ "version": "3.0.4-beta.9",
4
4
  "description": "Templates for the crawlee projects",
5
5
  "engines": {
6
6
  "node": ">=16.0.0"
@@ -0,0 +1,10 @@
1
+ # configurations
2
+ .idea
3
+
4
+ # crawlee and apify storage folders
5
+ apify_storage
6
+ crawlee_storage
7
+ storage
8
+
9
+ # installed files
10
+ node_modules
@@ -1,15 +1,29 @@
1
+ # Specify the base Docker image. You can read more about
2
+ # the available images at https://crawlee.dev/docs/guides/docker-images
3
+ # You can also use any other image from Docker Hub.
1
4
  FROM apify/actor-node:16
2
5
 
3
- # copy package.json, lock file and possibly crawlee.json
4
- COPY package*.json crawlee?json ./
5
- COPY src ./src
6
+ # Copy just package.json and package-lock.json
7
+ # to speed up the build using Docker layer cache.
8
+ COPY package*.json ./
6
9
 
7
- # install only prod deps
10
+ # Install NPM packages, skip optional and development dependencies to
11
+ # keep the image small. Avoid logging too much and print the dependency
12
+ # tree for debugging
8
13
  RUN npm --quiet set progress=false \
9
- && npm install --only=prod --no-optional \
14
+ && npm install --omit=dev --omit=optional \
10
15
  && echo "Installed NPM packages:" \
11
- && (npm list --only=prod --no-optional --all || true) \
16
+ && (npm list --omit=dev --all || true) \
12
17
  && echo "Node.js version:" \
13
18
  && node --version \
14
19
  && echo "NPM version:" \
15
20
  && npm --version
21
+
22
+ # Next, copy the remaining files and directories with the source code.
23
+ # Since we do this after NPM install, quick build will be really fast
24
+ # for most source file changes.
25
+ COPY . ./
26
+
27
+
28
+ # Run the image.
29
+ CMD npm start --silent
@@ -8,7 +8,6 @@
8
8
  },
9
9
  "scripts": {
10
10
  "start": "node src/main.js",
11
- "build": "tsc",
12
11
  "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
13
12
  },
14
13
  "author": "It's not you it's me",
@@ -3,19 +3,19 @@ import { Dataset, createCheerioRouter } from 'crawlee';
3
3
  export const router = createCheerioRouter();
4
4
 
5
5
  router.addDefaultHandler(async ({ enqueueLinks, log }) => {
6
- log.info(`Handle Start URLs`);
6
+ log.info(`enqueueing new URLs`);
7
7
  await enqueueLinks({
8
8
  globs: ['https://crawlee.dev/**'],
9
- label: 'DETAIL',
9
+ label: 'detail',
10
10
  });
11
11
  });
12
12
 
13
- router.addHandler('LIST', async ({ log }) => {
14
- log.info(`Handle pagination`);
15
- });
16
-
17
- router.addHandler('DETAIL', async ({ request, $, log }) => {
13
+ router.addHandler('detail', async ({ request, $, log }) => {
18
14
  const title = $('title').text();
19
- log.info(`Handle details: ${title} [${request.loadedUrl}]`);
20
- await Dataset.pushData({ url: request.loadedUrl });
15
+ log.info(`${title}`, { url: request.loadedUrl });
16
+
17
+ await Dataset.pushData({
18
+ url: request.loadedUrl,
19
+ title,
20
+ });
21
21
  });
@@ -0,0 +1,10 @@
1
+ # configurations
2
+ .idea
3
+
4
+ # crawlee and apify storage folders
5
+ apify_storage
6
+ crawlee_storage
7
+ storage
8
+
9
+ # installed files
10
+ node_modules
@@ -1,32 +1,50 @@
1
- # First, specify the base Docker image. You can read more about
1
+ # Specify the base Docker image. You can read more about
2
2
  # the available images at https://crawlee.dev/docs/guides/docker-images
3
3
  # You can also use any other image from Docker Hub.
4
4
  FROM apify/actor-node:16 AS builder
5
5
 
6
- # Second, copy the TS source files, package.json and package-lock.json since it should be
7
- # the only files that affects the installation and build in the next step
8
- COPY package*.json tsconfig.json crawlee?json ./
9
- COPY src ./src
6
+ # Copy just package.json and package-lock.json
7
+ # to speed up the build using Docker layer cache.
8
+ COPY package*.json ./
10
9
 
11
- # Install all dependencies (including dev deps) and build the project
12
- RUN npm install --include=dev && npm run build
10
+ # Install all dependencies. Don't audit to speed up the installation.
11
+ RUN npm install --include=dev --audit=false
12
+
13
+ # Next, copy the source files using the user set
14
+ # in the base image.
15
+ COPY . ./
16
+
17
+ # Install all dependencies and build the project.
18
+ # Don't audit to speed up the installation.
19
+ RUN npm run build
13
20
 
14
21
  # Create final image
15
22
  FROM apify/actor-node:16
16
23
 
17
- # Copy only necessary files (crawlee.json might not exist, so we need the regexp trick with `crawlee?json`)
18
- COPY --from=builder /usr/src/app/package.json /usr/src/app/crawlee?json ./
24
+ # Copy only built JS files from builder image
19
25
  COPY --from=builder /usr/src/app/dist ./dist
20
26
 
21
- # Install only prod deps
27
+ # Copy just package.json and package-lock.json
28
+ # to speed up the build using Docker layer cache.
29
+ COPY package*.json ./
30
+
31
+ # Install NPM packages, skip optional and development dependencies to
32
+ # keep the image small. Avoid logging too much and print the dependency
33
+ # tree for debugging
22
34
  RUN npm --quiet set progress=false \
23
- && npm install --only=prod --no-optional \
35
+ && npm install --omit=dev --omit=optional \
24
36
  && echo "Installed NPM packages:" \
25
- && (npm list --only=prod --no-optional --all || true) \
37
+ && (npm list --omit=dev --all || true) \
26
38
  && echo "Node.js version:" \
27
39
  && node --version \
28
40
  && echo "NPM version:" \
29
41
  && npm --version
30
42
 
31
- # Run compiled code
32
- CMD npm run start:prod
43
+ # Next, copy the remaining files and directories with the source code.
44
+ # Since we do this after NPM install, quick build will be really fast
45
+ # for most source file changes.
46
+ COPY . ./
47
+
48
+
49
+ # Run the image.
50
+ CMD npm run start:prod --silent
@@ -1,21 +1,21 @@
1
- import { createCheerioRouter, Dataset } from 'crawlee';
1
+ import { Dataset, createCheerioRouter } from 'crawlee';
2
2
 
3
3
  export const router = createCheerioRouter();
4
4
 
5
5
  router.addDefaultHandler(async ({ enqueueLinks, log }) => {
6
- log.info(`Handle Start URLs`);
6
+ log.info(`enqueueing new URLs`);
7
7
  await enqueueLinks({
8
8
  globs: ['https://crawlee.dev/**'],
9
- label: 'DETAIL',
9
+ label: 'detail',
10
10
  });
11
11
  });
12
12
 
13
- router.addHandler('LIST', async ({ log }) => {
14
- log.info(`Handle pagination`);
15
- });
16
-
17
- router.addHandler('DETAIL', async ({ request, $, log }) => {
13
+ router.addHandler('detail', async ({ request, $, log }) => {
18
14
  const title = $('title').text();
19
- log.info(`Handle details: ${title} [${request.loadedUrl}]`);
20
- await Dataset.pushData({ url: request.loadedUrl });
15
+ log.info(`${title}`, { url: request.loadedUrl });
16
+
17
+ await Dataset.pushData({
18
+ url: request.loadedUrl,
19
+ title,
20
+ });
21
21
  });
@@ -0,0 +1,10 @@
1
+ # configurations
2
+ .idea
3
+
4
+ # crawlee and apify storage folders
5
+ apify_storage
6
+ crawlee_storage
7
+ storage
8
+
9
+ # installed files
10
+ node_modules
@@ -0,0 +1,29 @@
1
+ # Specify the base Docker image. You can read more about
2
+ # the available images at https://crawlee.dev/docs/guides/docker-images
3
+ # You can also use any other image from Docker Hub.
4
+ FROM apify/actor-node-playwright-chrome:16
5
+
6
+ # Copy just package.json and package-lock.json
7
+ # to speed up the build using Docker layer cache.
8
+ COPY --chown=myuser package*.json ./
9
+
10
+ # Install NPM packages, skip optional and development dependencies to
11
+ # keep the image small. Avoid logging too much and print the dependency
12
+ # tree for debugging
13
+ RUN npm --quiet set progress=false \
14
+ && npm install --omit=dev --omit=optional \
15
+ && echo "Installed NPM packages:" \
16
+ && (npm list --omit=dev --all || true) \
17
+ && echo "Node.js version:" \
18
+ && node --version \
19
+ && echo "NPM version:" \
20
+ && npm --version
21
+
22
+ # Next, copy the remaining files and directories with the source code.
23
+ # Since we do this after NPM install, quick build will be really fast
24
+ # for most source file changes.
25
+ COPY --chown=myuser . ./
26
+
27
+
28
+ # Run the image.
29
+ CMD npm start --silent
@@ -0,0 +1,9 @@
1
+ # Getting started with Crawlee
2
+
3
+ This example uses `PlaywrightCrawler` to recursively crawl https://crawlee.dev using the browser automation library [Playwright](https://playwright.dev).
4
+
5
+ You can find more examples and documentation at the following links:
6
+
7
+ - [Step-by-step tutorial](https://crawlee.dev/docs/introduction) for Crawlee
8
+ - `PlaywrightCrawler` [API documentation](https://crawlee.dev/api/playwright-crawler/class/PlaywrightCrawler)
9
+ - Other [examples](https://crawlee.dev/docs/examples/playwright-crawler)
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "crawlee-getting-started-js",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "This is an example of a Crawlee project.",
6
+ "dependencies": {
7
+ "crawlee": "^3.0.0",
8
+ "playwright": "*"
9
+ },
10
+ "scripts": {
11
+ "start": "node src/main.js",
12
+ "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
13
+ },
14
+ "author": "It's not you it's me",
15
+ "license": "ISC"
16
+ }
@@ -0,0 +1,24 @@
1
+ // For more information, see https://crawlee.dev/
2
+ import { PlaywrightCrawler, Dataset } from 'crawlee';
3
+
4
+ // PlaywrightCrawler crawls the web using a headless
5
+ // browser controlled by the Playwright library.
6
+ const crawler = new PlaywrightCrawler({
7
+ // Use the requestHandler to process each of the crawled pages.
8
+ async requestHandler({ request, page, enqueueLinks, log }) {
9
+ const title = await page.title();
10
+ log.info(`Title of ${request.loadedUrl} is '${title}'`);
11
+
12
+ // Save results as JSON to ./storage/datasets/default
13
+ await Dataset.pushData({ title, url: request.loadedUrl });
14
+
15
+ // Extract links from the current page
16
+ // and add them to the crawling queue.
17
+ await enqueueLinks();
18
+ },
19
+ // Uncomment this option to see the browser window.
20
+ // headless: false,
21
+ });
22
+
23
+ // Add first URL to the queue and start the crawl.
24
+ await crawler.run(['https://crawlee.dev']);
@@ -0,0 +1,10 @@
1
+ # configurations
2
+ .idea
3
+
4
+ # crawlee and apify storage folders
5
+ apify_storage
6
+ crawlee_storage
7
+ storage
8
+
9
+ # installed files
10
+ node_modules
@@ -0,0 +1,51 @@
1
+ # Specify the base Docker image. You can read more about
2
+ # the available images at https://crawlee.dev/docs/guides/docker-images
3
+ # You can also use any other image from Docker Hub.
4
+ FROM apify/actor-node-playwright-chrome:16 AS builder
5
+
6
+ # Copy just package.json and package-lock.json
7
+ # to speed up the build using Docker layer cache.
8
+ COPY --chown=myuser package*.json ./
9
+
10
+ # Install all dependencies. Don't audit to speed up the installation.
11
+ RUN npm install --include=dev --audit=false
12
+
13
+ # Next, copy the source files using the user set
14
+ # in the base image.
15
+ COPY --chown=myuser . ./
16
+
17
+ # Install all dependencies and build the project.
18
+ # Don't audit to speed up the installation.
19
+ RUN npm run build
20
+
21
+ # Create final image
22
+ FROM apify/actor-node-playwright-chrome:16
23
+
24
+ # Copy only built JS files from builder image
25
+ COPY --from=builder --chown=myuser /home/myuser/dist ./dist
26
+
27
+ # Copy just package.json and package-lock.json
28
+ # to speed up the build using Docker layer cache.
29
+ COPY --chown=myuser package*.json ./
30
+
31
+ # Install NPM packages, skip optional and development dependencies to
32
+ # keep the image small. Avoid logging too much and print the dependency
33
+ # tree for debugging
34
+ RUN npm --quiet set progress=false \
35
+ && npm install --omit=dev --omit=optional \
36
+ && echo "Installed NPM packages:" \
37
+ && (npm list --omit=dev --all || true) \
38
+ && echo "Node.js version:" \
39
+ && node --version \
40
+ && echo "NPM version:" \
41
+ && npm --version
42
+
43
+ # Next, copy the remaining files and directories with the source code.
44
+ # Since we do this after NPM install, quick build will be really fast
45
+ # for most source file changes.
46
+ COPY --chown=myuser . ./
47
+
48
+
49
+ # Run the image. If you know you won't need headful browsers,
50
+ # you can remove the XVFB start script for a micro perf gain.
51
+ CMD ./start_xvfb_and_run_cmd.sh && npm run start:prod --silent
@@ -0,0 +1,9 @@
1
+ # Getting started with Crawlee
2
+
3
+ This example uses `PlaywrightCrawler` to recursively crawl https://crawlee.dev using the browser automation library [Playwright](https://playwright.dev).
4
+
5
+ You can find more examples and documentation at the following links:
6
+
7
+ - [Step-by-step tutorial](https://crawlee.dev/docs/introduction) for Crawlee
8
+ - `PlaywrightCrawler` [API documentation](https://crawlee.dev/api/playwright-crawler/class/PlaywrightCrawler)
9
+ - Other [examples](https://crawlee.dev/docs/examples/playwright-crawler)
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "crawlee-getting-started-ts",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "This is an example of a Crawlee project.",
6
+ "dependencies": {
7
+ "crawlee": "^3.0.0",
8
+ "playwright": "*"
9
+ },
10
+ "devDependencies": {
11
+ "@apify/tsconfig": "^0.1.0",
12
+ "ts-node": "^10.8.0",
13
+ "typescript": "^4.7.4"
14
+ },
15
+ "scripts": {
16
+ "start": "npm run start:dev",
17
+ "start:prod": "node dist/main.js",
18
+ "start:dev": "ts-node-esm -T src/main.ts",
19
+ "build": "tsc",
20
+ "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
21
+ },
22
+ "author": "It's not you it's me",
23
+ "license": "ISC"
24
+ }
@@ -0,0 +1,24 @@
1
+ // For more information, see https://crawlee.dev/
2
+ import { PlaywrightCrawler, Dataset } from 'crawlee';
3
+
4
+ // PlaywrightCrawler crawls the web using a headless
5
+ // browser controlled by the Playwright library.
6
+ const crawler = new PlaywrightCrawler({
7
+ // Use the requestHandler to process each of the crawled pages.
8
+ async requestHandler({ request, page, enqueueLinks, log }) {
9
+ const title = await page.title();
10
+ log.info(`Title of ${request.loadedUrl} is '${title}'`);
11
+
12
+ // Save results as JSON to ./storage/datasets/default
13
+ await Dataset.pushData({ title, url: request.loadedUrl });
14
+
15
+ // Extract links from the current page
16
+ // and add them to the crawling queue.
17
+ await enqueueLinks();
18
+ },
19
+ // Uncomment this option to see the browser window.
20
+ // headless: false,
21
+ });
22
+
23
+ // Add first URL to the queue and start the crawl.
24
+ await crawler.run(['https://crawlee.dev']);
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "@apify/tsconfig",
3
+ "compilerOptions": {
4
+ "module": "ES2022",
5
+ "target": "ES2022",
6
+ "outDir": "dist",
7
+ "noUnusedLocals": false,
8
+ "lib": ["DOM"]
9
+ },
10
+ "include": [
11
+ "./src/**/*"
12
+ ]
13
+ }
@@ -0,0 +1,10 @@
1
+ # configurations
2
+ .idea
3
+
4
+ # crawlee and apify storage folders
5
+ apify_storage
6
+ crawlee_storage
7
+ storage
8
+
9
+ # installed files
10
+ node_modules
@@ -1,15 +1,29 @@
1
+ # Specify the base Docker image. You can read more about
2
+ # the available images at https://crawlee.dev/docs/guides/docker-images
3
+ # You can also use any other image from Docker Hub.
1
4
  FROM apify/actor-node-playwright-chrome:16
2
5
 
3
- # copy package.json, lock file and possibly crawlee.json
4
- COPY package*.json crawlee?json ./
5
- COPY src ./src
6
+ # Copy just package.json and package-lock.json
7
+ # to speed up the build using Docker layer cache.
8
+ COPY --chown=myuser package*.json ./
6
9
 
7
- # install only prod deps
10
+ # Install NPM packages, skip optional and development dependencies to
11
+ # keep the image small. Avoid logging too much and print the dependency
12
+ # tree for debugging
8
13
  RUN npm --quiet set progress=false \
9
- && npm install --only=prod --no-optional \
14
+ && npm install --omit=dev --omit=optional \
10
15
  && echo "Installed NPM packages:" \
11
- && (npm list --only=prod --no-optional --all || true) \
16
+ && (npm list --omit=dev --all || true) \
12
17
  && echo "Node.js version:" \
13
18
  && node --version \
14
19
  && echo "NPM version:" \
15
20
  && npm --version
21
+
22
+ # Next, copy the remaining files and directories with the source code.
23
+ # Since we do this after NPM install, quick build will be really fast
24
+ # for most source file changes.
25
+ COPY --chown=myuser . ./
26
+
27
+
28
+ # Run the image.
29
+ CMD npm start --silent
@@ -6,21 +6,3 @@ If you're looking for examples or want to learn more visit:
6
6
 
7
7
  - [Documentation](https://crawlee.dev/api/playwright-crawler/class/PlaywrightCrawler)
8
8
  - [Examples](https://crawlee.dev/docs/examples/playwright-crawler)
9
-
10
- ## Writing a README
11
-
12
- See our tutorial on [writing READMEs for your actors](https://help.apify.com/en/articles/2912548-how-to-write-great-readme-for-your-actors) if you need more inspiration.
13
-
14
- ### Table of contents
15
-
16
- If your README requires a table of contents, use the template below and make sure to keep the `<!-- toc start -->` and `<!-- toc end -->` markers.
17
-
18
- <!-- toc start -->
19
- - Introduction
20
- - Use Cases
21
- - Case 1
22
- - Case 2
23
- - Input
24
- - Output
25
- - Miscellaneous
26
- <!-- toc end -->
@@ -9,7 +9,6 @@
9
9
  },
10
10
  "scripts": {
11
11
  "start": "node src/main.js",
12
- "build": "tsc",
13
12
  "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
14
13
  },
15
14
  "author": "It's not you it's me",
@@ -3,19 +3,19 @@ import { Dataset, createPlaywrightRouter } from 'crawlee';
3
3
  export const router = createPlaywrightRouter();
4
4
 
5
5
  router.addDefaultHandler(async ({ enqueueLinks, log }) => {
6
- log.info(`Handle Start URLs`);
6
+ log.info(`enqueueing new URLs`);
7
7
  await enqueueLinks({
8
8
  globs: ['https://crawlee.dev/**'],
9
- label: 'DETAIL',
9
+ label: 'detail',
10
10
  });
11
11
  });
12
12
 
13
- router.addHandler('handleList', async ({ log }) => {
14
- log.info(`Handle pagination`);
15
- });
16
-
17
- router.addHandler('handleDetail', async ({ request, page, log }) => {
13
+ router.addHandler('detail', async ({ request, page, log }) => {
18
14
  const title = await page.title();
19
- log.info(`Handle details: ${title} [${request.loadedUrl}]`);
20
- await Dataset.pushData({ url: request.loadedUrl });
15
+ log.info(`${title}`, { url: request.loadedUrl });
16
+
17
+ await Dataset.pushData({
18
+ url: request.loadedUrl,
19
+ title,
20
+ });
21
21
  });
@@ -0,0 +1,10 @@
1
+ # configurations
2
+ .idea
3
+
4
+ # crawlee and apify storage folders
5
+ apify_storage
6
+ crawlee_storage
7
+ storage
8
+
9
+ # installed files
10
+ node_modules
@@ -1,32 +1,51 @@
1
- # First, specify the base Docker image. You can read more about
1
+ # Specify the base Docker image. You can read more about
2
2
  # the available images at https://crawlee.dev/docs/guides/docker-images
3
3
  # You can also use any other image from Docker Hub.
4
- FROM apify/actor-node:16 AS builder
4
+ FROM apify/actor-node-playwright-chrome:16 AS builder
5
5
 
6
- # Second, copy the TS source files, package.json and package-lock.json since it should be
7
- # the only files that affects the installation and build in the next step
8
- COPY package*.json tsconfig.json crawlee?json ./
9
- COPY src ./src
6
+ # Copy just package.json and package-lock.json
7
+ # to speed up the build using Docker layer cache.
8
+ COPY --chown=myuser package*.json ./
10
9
 
11
- # Install all dependencies (including dev deps) and build the project
12
- RUN npm install --include=dev && npm run build
10
+ # Install all dependencies. Don't audit to speed up the installation.
11
+ RUN npm install --include=dev --audit=false
12
+
13
+ # Next, copy the source files using the user set
14
+ # in the base image.
15
+ COPY --chown=myuser . ./
16
+
17
+ # Install all dependencies and build the project.
18
+ # Don't audit to speed up the installation.
19
+ RUN npm run build
13
20
 
14
21
  # Create final image
15
22
  FROM apify/actor-node-playwright-chrome:16
16
23
 
17
- # Copy only necessary files (crawlee.json might not exist, so we need the regexp trick with `crawlee?json`)
18
- COPY --from=builder /usr/src/app/package.json /usr/src/app/crawlee?json ./
19
- COPY --from=builder /usr/src/app/dist ./dist
24
+ # Copy only built JS files from builder image
25
+ COPY --from=builder --chown=myuser /home/myuser/dist ./dist
26
+
27
+ # Copy just package.json and package-lock.json
28
+ # to speed up the build using Docker layer cache.
29
+ COPY --chown=myuser package*.json ./
20
30
 
21
- # Install only prod deps
31
+ # Install NPM packages, skip optional and development dependencies to
32
+ # keep the image small. Avoid logging too much and print the dependency
33
+ # tree for debugging
22
34
  RUN npm --quiet set progress=false \
23
- && npm install --only=prod --no-optional \
35
+ && npm install --omit=dev --omit=optional \
24
36
  && echo "Installed NPM packages:" \
25
- && (npm list --only=prod --no-optional --all || true) \
37
+ && (npm list --omit=dev --all || true) \
26
38
  && echo "Node.js version:" \
27
39
  && node --version \
28
40
  && echo "NPM version:" \
29
41
  && npm --version
30
42
 
31
- # Run compiled code
32
- CMD ./start_xvfb_and_run_cmd.sh && npm run start:prod
43
+ # Next, copy the remaining files and directories with the source code.
44
+ # Since we do this after NPM install, quick build will be really fast
45
+ # for most source file changes.
46
+ COPY --chown=myuser . ./
47
+
48
+
49
+ # Run the image. If you know you won't need headful browsers,
50
+ # you can remove the XVFB start script for a micro perf gain.
51
+ CMD ./start_xvfb_and_run_cmd.sh && npm run start:prod --silent
@@ -6,21 +6,3 @@ If you're looking for examples or want to learn more visit:
6
6
 
7
7
  - [Documentation](https://crawlee.dev/api/playwright-crawler/class/PlaywrightCrawler)
8
8
  - [Examples](https://crawlee.dev/docs/examples/playwright-crawler)
9
-
10
- ## Writing a README
11
-
12
- See our tutorial on [writing READMEs for your actors](https://help.apify.com/en/articles/2912548-how-to-write-great-readme-for-your-actors) if you need more inspiration.
13
-
14
- ### Table of contents
15
-
16
- If your README requires a table of contents, use the template below and make sure to keep the `<!-- toc start -->` and `<!-- toc end -->` markers.
17
-
18
- <!-- toc start -->
19
- - Introduction
20
- - Use Cases
21
- - Case 1
22
- - Case 2
23
- - Input
24
- - Output
25
- - Miscellaneous
26
- <!-- toc end -->
@@ -3,19 +3,19 @@ import { Dataset, createPlaywrightRouter } from 'crawlee';
3
3
  export const router = createPlaywrightRouter();
4
4
 
5
5
  router.addDefaultHandler(async ({ enqueueLinks, log }) => {
6
- log.info(`Handle Start URLs`);
6
+ log.info(`enqueueing new URLs`);
7
7
  await enqueueLinks({
8
8
  globs: ['https://crawlee.dev/**'],
9
- label: 'DETAIL',
9
+ label: 'detail',
10
10
  });
11
11
  });
12
12
 
13
- router.addHandler('handleList', async ({ log }) => {
14
- log.info(`Handle pagination`);
15
- });
16
-
17
- router.addHandler('handleDetail', async ({ request, page, log }) => {
13
+ router.addHandler('detail', async ({ request, page, log }) => {
18
14
  const title = await page.title();
19
- log.info(`Handle details: ${title} [${request.loadedUrl}]`);
20
- await Dataset.pushData({ url: request.loadedUrl });
15
+ log.info(`${title}`, { url: request.loadedUrl });
16
+
17
+ await Dataset.pushData({
18
+ url: request.loadedUrl,
19
+ title,
20
+ });
21
21
  });
@@ -0,0 +1,10 @@
1
+ # configurations
2
+ .idea
3
+
4
+ # crawlee and apify storage folders
5
+ apify_storage
6
+ crawlee_storage
7
+ storage
8
+
9
+ # installed files
10
+ node_modules
@@ -1,15 +1,29 @@
1
+ # Specify the base Docker image. You can read more about
2
+ # the available images at https://crawlee.dev/docs/guides/docker-images
3
+ # You can also use any other image from Docker Hub.
1
4
  FROM apify/actor-node-puppeteer-chrome:16
2
5
 
3
- # copy package.json, lock file and possibly crawlee.json
4
- COPY package*.json crawlee?json ./
5
- COPY src ./src
6
+ # Copy just package.json and package-lock.json
7
+ # to speed up the build using Docker layer cache.
8
+ COPY --chown=myuser package*.json ./
6
9
 
7
- # install only prod deps
10
+ # Install NPM packages, skip optional and development dependencies to
11
+ # keep the image small. Avoid logging too much and print the dependency
12
+ # tree for debugging
8
13
  RUN npm --quiet set progress=false \
9
- && npm install --only=prod --no-optional \
14
+ && npm install --omit=dev --omit=optional \
10
15
  && echo "Installed NPM packages:" \
11
- && (npm list --only=prod --no-optional --all || true) \
16
+ && (npm list --omit=dev --all || true) \
12
17
  && echo "Node.js version:" \
13
18
  && node --version \
14
19
  && echo "NPM version:" \
15
20
  && npm --version
21
+
22
+ # Next, copy the remaining files and directories with the source code.
23
+ # Since we do this after NPM install, quick build will be really fast
24
+ # for most source file changes.
25
+ COPY --chown=myuser . ./
26
+
27
+
28
+ # Run the image.
29
+ CMD npm start --silent
@@ -6,21 +6,3 @@ If you're looking for examples or want to learn more visit:
6
6
 
7
7
  - [Documentation](https://crawlee.dev/api/puppeteer-crawler/class/PuppeteerCrawler)
8
8
  - [Examples](https://crawlee.dev/docs/examples/puppeteer-crawler)
9
-
10
- ## Writing a README
11
-
12
- See our tutorial on [writing READMEs for your actors](https://help.apify.com/en/articles/2912548-how-to-write-great-readme-for-your-actors) if you need more inspiration.
13
-
14
- ### Table of contents
15
-
16
- If your README requires a table of contents, use the template below and make sure to keep the `<!-- toc start -->` and `<!-- toc end -->` markers.
17
-
18
- <!-- toc start -->
19
- - Introduction
20
- - Use Cases
21
- - Case 1
22
- - Case 2
23
- - Input
24
- - Output
25
- - Miscellaneous
26
- <!-- toc end -->
@@ -9,7 +9,6 @@
9
9
  },
10
10
  "scripts": {
11
11
  "start": "node src/main.js",
12
- "build": "tsc",
13
12
  "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
14
13
  },
15
14
  "author": "It's not you it's me",
@@ -3,19 +3,19 @@ import { Dataset, createPuppeteerRouter } from 'crawlee';
3
3
  export const router = createPuppeteerRouter();
4
4
 
5
5
  router.addDefaultHandler(async ({ enqueueLinks, log }) => {
6
- log.info(`Handle Start URLs`);
6
+ log.info(`enqueueing new URLs`);
7
7
  await enqueueLinks({
8
8
  globs: ['https://crawlee.dev/**'],
9
- label: 'DETAIL',
9
+ label: 'detail',
10
10
  });
11
11
  });
12
12
 
13
- router.addHandler('handleList', async ({ log }) => {
14
- log.info(`Handle pagination`);
15
- });
16
-
17
- router.addHandler('handleDetail', async ({ request, page, log }) => {
13
+ router.addHandler('detail', async ({ request, page, log }) => {
18
14
  const title = await page.title();
19
- log.info(`Handle details: ${title} [${request.loadedUrl}]`);
20
- await Dataset.pushData({ url: request.loadedUrl });
15
+ log.info(`${title}`, { url: request.loadedUrl });
16
+
17
+ await Dataset.pushData({
18
+ url: request.loadedUrl,
19
+ title,
20
+ });
21
21
  });
@@ -0,0 +1,10 @@
1
+ # configurations
2
+ .idea
3
+
4
+ # crawlee and apify storage folders
5
+ apify_storage
6
+ crawlee_storage
7
+ storage
8
+
9
+ # installed files
10
+ node_modules
@@ -1,32 +1,51 @@
1
- # First, specify the base Docker image. You can read more about
1
+ # Specify the base Docker image. You can read more about
2
2
  # the available images at https://crawlee.dev/docs/guides/docker-images
3
3
  # You can also use any other image from Docker Hub.
4
- FROM apify/actor-node:16 AS builder
4
+ FROM apify/actor-node-puppeteer-chrome:16 AS builder
5
5
 
6
- # Second, copy the TS source files, package.json and package-lock.json since it should be
7
- # the only files that affects the installation and build in the next step
8
- COPY package*.json tsconfig.json crawlee?json ./
9
- COPY src ./src
6
+ # Copy just package.json and package-lock.json
7
+ # to speed up the build using Docker layer cache.
8
+ COPY --chown=myuser package*.json ./
10
9
 
11
- # Install all dependencies (including dev deps) and build the project
12
- RUN npm install --include=dev && npm run build
10
+ # Install all dependencies. Don't audit to speed up the installation.
11
+ RUN npm install --include=dev --audit=false
12
+
13
+ # Next, copy the source files using the user set
14
+ # in the base image.
15
+ COPY --chown=myuser . ./
16
+
17
+ # Install all dependencies and build the project.
18
+ # Don't audit to speed up the installation.
19
+ RUN npm run build
13
20
 
14
21
  # Create final image
15
22
  FROM apify/actor-node-puppeteer-chrome:16
16
23
 
17
- # Copy only necessary files (crawlee.json might not exist, so we need the regexp trick with `crawlee?json`)
18
- COPY --from=builder /usr/src/app/package.json /usr/src/app/crawlee?json ./
19
- COPY --from=builder /usr/src/app/dist ./dist
24
+ # Copy only built JS files from builder image
25
+ COPY --from=builder --chown=myuser /home/myuser/dist ./dist
26
+
27
+ # Copy just package.json and package-lock.json
28
+ # to speed up the build using Docker layer cache.
29
+ COPY --chown=myuser package*.json ./
20
30
 
21
- # Install only prod deps
31
+ # Install NPM packages, skip optional and development dependencies to
32
+ # keep the image small. Avoid logging too much and print the dependency
33
+ # tree for debugging
22
34
  RUN npm --quiet set progress=false \
23
- && npm install --only=prod --no-optional \
35
+ && npm install --omit=dev --omit=optional \
24
36
  && echo "Installed NPM packages:" \
25
- && (npm list --only=prod --no-optional --all || true) \
37
+ && (npm list --omit=dev --all || true) \
26
38
  && echo "Node.js version:" \
27
39
  && node --version \
28
40
  && echo "NPM version:" \
29
41
  && npm --version
30
42
 
31
- # Run compiled code
32
- CMD ./start_xvfb_and_run_cmd.sh && npm run start:prod
43
+ # Next, copy the remaining files and directories with the source code.
44
+ # Since we do this after NPM install, quick build will be really fast
45
+ # for most source file changes.
46
+ COPY --chown=myuser . ./
47
+
48
+
49
+ # Run the image. If you know you won't need headful browsers,
50
+ # you can remove the XVFB start script for a micro perf gain.
51
+ CMD ./start_xvfb_and_run_cmd.sh && npm run start:prod --silent
@@ -6,21 +6,3 @@ If you're looking for examples or want to learn more visit:
6
6
 
7
7
  - [Documentation](https://crawlee.dev/api/puppeteer-crawler/class/PuppeteerCrawler)
8
8
  - [Examples](https://crawlee.dev/docs/examples/puppeteer-crawler)
9
-
10
- ## Writing a README
11
-
12
- See our tutorial on [writing READMEs for your actors](https://help.apify.com/en/articles/2912548-how-to-write-great-readme-for-your-actors) if you need more inspiration.
13
-
14
- ### Table of contents
15
-
16
- If your README requires a table of contents, use the template below and make sure to keep the `<!-- toc start -->` and `<!-- toc end -->` markers.
17
-
18
- <!-- toc start -->
19
- - Introduction
20
- - Use Cases
21
- - Case 1
22
- - Case 2
23
- - Input
24
- - Output
25
- - Miscellaneous
26
- <!-- toc end -->
@@ -3,19 +3,19 @@ import { Dataset, createPuppeteerRouter } from 'crawlee';
3
3
  export const router = createPuppeteerRouter();
4
4
 
5
5
  router.addDefaultHandler(async ({ enqueueLinks, log }) => {
6
- log.info(`Handle Start URLs`);
6
+ log.info(`enqueueing new URLs`);
7
7
  await enqueueLinks({
8
8
  globs: ['https://crawlee.dev/**'],
9
- label: 'DETAIL',
9
+ label: 'detail',
10
10
  });
11
11
  });
12
12
 
13
- router.addHandler('handleList', async ({ log }) => {
14
- log.info(`Handle pagination`);
15
- });
16
-
17
- router.addHandler('handleDetail', async ({ request, page, log }) => {
13
+ router.addHandler('detail', async ({ request, page, log }) => {
18
14
  const title = await page.title();
19
- log.info(`Handle details: ${title} [${request.loadedUrl}]`);
20
- await Dataset.pushData({ url: request.loadedUrl });
15
+ log.info(`${title}`, { url: request.loadedUrl });
16
+
17
+ await Dataset.pushData({
18
+ url: request.loadedUrl,
19
+ title,
20
+ });
21
21
  });