apify 3.0.0-beta.7 → 3.0.0-beta.72

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.
package/README.md CHANGED
@@ -1,183 +1,144 @@
1
- # Crawlee: The scalable web crawling and scraping library for JavaScript
2
-
3
- <!-- Mirror this part to src/index.js -->
4
-
5
- [![NPM dev version](https://img.shields.io/npm/v/@crawlee/core/next.svg)](https://www.npmjs.com/package/@crawlee/core)
6
- [![Downloads](https://img.shields.io/npm/dm/@crawlee/core.svg)](https://www.npmjs.com/package/@crawlee/core)
7
- [![Chat on discord](https://img.shields.io/discord/801163717915574323?label=discord)](https://discord.gg/jyEM2PRvMU)
8
- [![Build Status](https://github.com/apify/apify-ts/actions/workflows/test-and-release.yml/badge.svg?branch=master)](https://github.com/apify/apify-ts/actions/workflows/test-and-release.yml)
9
-
10
- Apify SDK simplifies the development of web crawlers, scrapers, data extractors and web automation jobs.
1
+ <h1 align="center">
2
+ <a href="https://apify.github.io/apify-ts/">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/apify-ts/master/website/static/img/crawlee-dark.svg?sanitize=true">
5
+ <img alt="Crawlee" src="https://raw.githubusercontent.com/apify/apify-ts/master/website/static/img/crawlee-light.svg?sanitize=true" width="500">
6
+ </picture>
7
+ </a>
8
+ <br>
9
+ <small>The scalable web crawling and scraping library for JavaScript</small>
10
+ </h1>
11
+
12
+ <p align=center>
13
+ <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/v/@crawlee/core/next.svg" alt="NPM dev version" data-canonical-src="https://img.shields.io/npm/v/@crawlee/core/next.svg" style="max-width: 100%;"></a>
14
+ <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/dm/@crawlee/core.svg" alt="Downloads" data-canonical-src="https://img.shields.io/npm/dm/@crawlee/core.svg" style="max-width: 100%;"></a>
15
+ <a href="https://discord.gg/jyEM2PRvMU" rel="nofollow"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on discord" data-canonical-src="https://img.shields.io/discord/801163717915574323?label=discord" style="max-width: 100%;"></a>
16
+ <a href="https://github.com/apify/apify-ts/actions/workflows/test-and-release.yml"><img src="https://github.com/apify/apify-ts/actions/workflows/test-and-release.yml/badge.svg?branch=master" alt="Build Status" style="max-width: 100%;"></a>
17
+ </p>
18
+
19
+ Crawlee simplifies the development of web crawlers, scrapers, data extractors and web automation jobs.
11
20
  It provides tools to manage and automatically scale a pool of headless browsers,
12
21
  to maintain queues of URLs to crawl, store crawling results to a local filesystem or into the cloud,
13
22
  rotate proxies and much more.
14
- The SDK is available as the [`apify`](https://www.npmjs.com/package/apify) NPM package.
23
+ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) NPM package.
15
24
  It can be used either stand-alone in your own applications
16
25
  or in [actors](https://docs.apify.com/actor)
17
26
  running on the [Apify Cloud](https://apify.com/).
18
27
 
19
- **View full documentation, guides and examples on the [Apify SDK project website](https://sdk.apify.com)**
28
+ **View full documentation, guides and examples on the [Crawlee project website](https://apify.github.io/apify-ts/)**
20
29
 
21
- > Would you like to work with us on Apify SDK or similar projects? [We are hiring!](https://apify.com/jobs#senior-node.js-engineer)
30
+ > Would you like to work with us on Crawlee or similar projects? [We are hiring!](https://apify.com/jobs#senior-node.js-engineer)
22
31
 
23
32
  ## Motivation
24
33
 
25
- Thanks to tools like [Playwright](https://github.com/microsoft/playwright), [Puppeteer](https://github.com/puppeteer/puppeteer) or
26
- [Cheerio](https://www.npmjs.com/package/cheerio), it is easy to write Node.js code to extract data from web pages. But
27
- eventually things will get complicated. For example, when you try to:
34
+ 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:
28
35
 
29
36
  - Perform a deep crawl of an entire website using a persistent queue of URLs.
30
37
  - Run your scraping code on a list of 100k URLs in a CSV file, without losing any data when your code crashes.
31
38
  - Rotate proxies to hide your browser origin and keep user-like sessions.
32
39
  - Disable browser fingerprinting protections used by websites.
33
40
 
34
- Python has [Scrapy](https://scrapy.org/) for these tasks, but there was no such library for **JavaScript, the language of
35
- 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
36
- browser.
41
+ 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.
37
42
 
38
- The goal of the Apify SDK is to fill this gap and provide a toolbox for generic web scraping, crawling and automation tasks in JavaScript. So don't
39
- reinvent the wheel every time you need data from the web, and focus on writing code specific to the target website, rather than developing
40
- commonalities.
43
+ 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.
41
44
 
42
45
  ## Overview
43
46
 
44
- The Apify SDK is available as the [`apify`](https://www.npmjs.com/package/apify) NPM package and it provides the following tools:
47
+ 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:
45
48
 
46
- - [`CheerioCrawler`](https://sdk.apify.com/docs/api/cheerio-crawler) - Enables the parallel crawling of a large
47
- number of web pages using the [cheerio](https://www.npmjs.com/package/cheerio) HTML parser. This is the most
48
- efficient web crawler, but it does not work on websites that require JavaScript.
49
+ - [`CheerioCrawler`](https://apify.github.io/apify-ts/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.
49
50
 
50
- - [`PuppeteerCrawler`](https://sdk.apify.com/docs/api/puppeteer-crawler) - Enables the parallel crawling of
51
- a large number of web pages using the headless Chrome browser and [Puppeteer](https://github.com/puppeteer/puppeteer).
52
- The pool of Chrome browsers is automatically scaled up and down based on available system resources.
51
+ - [`PuppeteerCrawler`](https://apify.github.io/apify-ts/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.
53
52
 
54
- - [`PlaywrightCrawler`](https://sdk.apify.com/docs/api/playwright-crawler) - Unlike `PuppeteerCrawler`
55
- you can use [Playwright](https://github.com/microsoft/playwright) to manage almost any headless browser.
56
- It also provides a cleaner and more mature interface while keeping the ease of use and advanced features.
53
+ - [`PlaywrightCrawler`](https://apify.github.io/apify-ts/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.
57
54
 
58
- - [`BasicCrawler`](https://sdk.apify.com/docs/api/basic-crawler) - Provides a simple framework for the parallel
59
- crawling of web pages whose URLs are fed either from a static list or from a dynamic queue of URLs. This class
60
- serves as a base for the more specialized crawlers above.
55
+ - [`BasicCrawler`](https://apify.github.io/apify-ts/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.
61
56
 
62
- - [`RequestList`](https://sdk.apify.com/docs/api/request-list) - Represents a list of URLs to crawl.
63
- The URLs can be passed in code or in a text file hosted on the web. The list persists its state so that crawling
64
- can resume when the Node.js process restarts.
57
+ - [`RequestList`](https://apify.github.io/apify-ts/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.
65
58
 
66
- - [`RequestQueue`](https://sdk.apify.com/docs/api/request-queue) - Represents a queue of URLs to crawl,
67
- which is stored either on a local filesystem or in the [Apify Cloud](https://apify.com). The queue is used
68
- for deep crawling of websites, where you start with several URLs and then recursively follow links to other pages.
69
- The data structure supports both breadth-first and depth-first crawling orders.
59
+ - [`RequestQueue`](https://apify.github.io/apify-ts/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.
70
60
 
71
- - [`Dataset`](https://sdk.apify.com/docs/api/dataset) - Provides a store for structured data and enables their export
72
- to formats like JSON, JSONL, CSV, XML, Excel or HTML. The data is stored on a local filesystem or in the Apify Cloud.
73
- Datasets are useful for storing and sharing large tabular crawling results, such as a list of products or real estate offers.
61
+ - [`Dataset`](https://apify.github.io/apify-ts/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.
74
62
 
75
- - [`KeyValueStore`](https://sdk.apify.com/docs/api/key-value-store) - A simple key-value store for arbitrary data
76
- records or files, along with their MIME content type. It is ideal for saving screenshots of web pages, PDFs
77
- or to persist the state of your crawlers. The data is stored on a local filesystem or in the Apify Cloud.
63
+ - [`KeyValueStore`](https://apify.github.io/apify-ts/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.
78
64
 
79
- - [`AutoscaledPool`](https://sdk.apify.com/docs/api/autoscaled-pool) - Runs asynchronous background tasks,
80
- while automatically adjusting the concurrency based on free system memory and CPU usage. This is useful for running
81
- web scraping tasks at the maximum capacity of the system.
65
+ - [`AutoscaledPool`](https://apify.github.io/apify-ts/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.
82
66
 
83
- - [`Browser Utils`](https://sdk.apify.com/docs/api/puppeteer) - Provides several helper functions useful
84
- for web scraping. For example, to inject jQuery into web pages or to hide browser origin.
85
-
86
- Additionally, the package provides various helper functions to simplify running your code on the Apify Cloud and thus
87
- take advantage of its pool of proxies, job scheduler, data storage, etc.
88
- For more information, see the [Apify SDK Programmer's Reference](https://sdk.apify.com).
67
+ 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://apify.github.io/apify-ts/).
89
68
 
90
69
  ## Quick Start
91
70
 
92
- This short tutorial will set you up to start using Apify SDK in a minute or two.
93
- If you want to learn more, proceed to the [Getting Started](https://sdk.apify.com/docs/guides/getting-started)
94
- tutorial that will take you step by step through creating your first scraper.
71
+ 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://apify.github.io/apify-ts/docs/guides/getting-started) tutorial that will take you step by step through creating your first scraper.
95
72
 
96
73
  ### Local stand-alone usage
97
74
 
98
- Apify SDK requires [Node.js](https://nodejs.org/en/) 15.10 or later.
99
- Add Apify SDK to any Node.js project by running:
75
+ Crawlee requires [Node.js](https://nodejs.org/en/) 16 or later. Add Crawlee to any Node.js project by running:
100
76
 
101
77
  ```bash
102
- npm install apify playwright
78
+ npm install crawlee playwright
103
79
  ```
104
80
 
105
- > Neither `playwright` nor `puppeteer` are bundled with the SDK to reduce install size and allow greater
106
- > flexibility. That's why we install it with NPM. You can choose one, both, or neither.
81
+ > 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.
107
82
 
108
- Run the following example to perform a recursive crawl of a website using Playwright. For more examples showcasing various features of the Apify SDK,
109
- [see the Examples section of the documentation](https://sdk.apify.com/docs/examples/crawl-multiple-urls).
83
+ 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://apify.github.io/apify-ts/docs/examples/crawl-multiple-urls).
110
84
 
111
85
  ```javascript
112
- const Apify = require('apify');
113
-
114
- // Apify.main is a helper function, you don't need to use it.
115
- Apify.main(async () => {
116
- const requestQueue = await Apify.openRequestQueue();
117
- // Choose the first URL to open.
118
- await requestQueue.addRequest({ url: 'https://www.iana.org/' });
119
-
120
- const crawler = new Apify.PlaywrightCrawler({
121
- requestQueue,
122
- handlePageFunction: async ({ request, page }) => {
123
- // Extract HTML title of the page.
124
- const title = await page.title();
125
- console.log(`Title of ${request.url}: ${title}`);
126
-
127
- // Add URLs that match the provided pattern.
128
- await Apify.utils.enqueueLinks({
129
- page,
130
- requestQueue,
131
- pseudoUrls: ['https://www.iana.org/[.*]'],
132
- });
133
- },
134
- });
135
-
136
- await crawler.run();
86
+ import { PlaywrightCrawler } from 'crawlee';
87
+
88
+ const crawler = new PlaywrightCrawler({
89
+ async requestHandler({ request, page, enqueueLinks }) {
90
+ // Extract HTML title of the page.
91
+ const title = await page.title();
92
+ console.log(`Title of ${request.url}: ${title}`);
93
+
94
+ // Add URLs from the same subdomain.
95
+ await enqueueLinks();
96
+ },
137
97
  });
98
+
99
+ // Choose the first URL to open and run the crawler.
100
+ await crawler.addRequests(['https://www.iana.org/']);
101
+ await crawler.run();
138
102
  ```
139
103
 
140
- When you run the example, you should see Apify SDK automating a Chrome browser.
104
+ When you run the example, you should see Crawlee automating a Chrome browser.
141
105
 
142
- ![Chrome Scrape](https://sdk.apify.com/img/chrome_scrape.gif)
106
+ ![Chrome Scrape](https://apify.github.io/apify-ts/img/chrome_scrape.gif)
143
107
 
144
- By default, Apify SDK stores data to `./apify_storage` in the current working directory. You can override this behavior by setting either the
145
- `APIFY_LOCAL_STORAGE_DIR` or `APIFY_TOKEN` environment variable. For details, see [Environment variables](https://sdk.apify.com/docs/guides/environment-variables), [Request storage](https://sdk.apify.com/docs/guides/request-storage) and [Result storage](https://sdk.apify.com/docs/guides/result-storage).
108
+ By default, Crawlee stores data to `./crawlee_storage` in the current working directory. You can override this directory via `CRAWLEE_STORAGE_DIR` env var. For details, see [Environment variables](https://apify.github.io/apify-ts/docs/guides/environment-variables), [Request storage](https://apify.github.io/apify-ts/docs/guides/request-storage) and [Result storage](https://apify.github.io/apify-ts/docs/guides/result-storage).
146
109
 
147
- ### Local usage with Apify command-line interface (CLI)
110
+ ### Local usage with Crawlee command-line interface (CLI)
148
111
 
149
- To avoid the need to set the environment variables manually, to create a boilerplate of your project, and to enable pushing and running your code on
150
- the [Apify platform](https://sdk.apify.com/docs/guides/apify-platform), you can use the [Apify command-line interface (CLI)](https://github.com/apify/apify-cli) tool.
112
+ To create a boilerplate of your project we can use the [Crawlee command-line interface (CLI)](https://github.com/apify/apify-cli) tool.
151
113
 
152
- Install the CLI by running:
114
+ Let's create a boilerplate of your new web crawling project by running:
153
115
 
154
116
  ```bash
155
- npm -g install apify-cli
117
+ npx crawlee create my-hello-world
156
118
  ```
157
119
 
158
- Now create a boilerplate of your new web crawling project by running:
120
+ 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:
159
121
 
160
122
  ```bash
161
- apify create my-hello-world
123
+ cd my-hello-world
124
+ npx crawlee run
162
125
  ```
163
126
 
164
- 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`
165
- with a Node.js project files. You can run the project as follows:
127
+ By default, the crawling data will be stored in a local directory at `./crawlee_storage`. For example, the input JSON file for the actor is expected to be in the default key-value store in `./crawlee_storage/key_value_stores/default/INPUT.json`.
166
128
 
167
- ```bash
168
- cd my-hello-world
169
- apify run
170
- ```
129
+ ### Usage on the Apify platform
171
130
 
172
- By default, the crawling data will be stored in a local directory at `./apify_storage`. For example, the input JSON file for the actor is expected to
173
- be in the default key-value store in `./apify_storage/key_value_stores/default/INPUT.json`.
131
+ 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:
174
132
 
175
- Now you can easily deploy your code to the Apify platform by running:
133
+ > 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.
176
134
 
177
135
  ```bash
136
+ npm i -g apify-cli
178
137
  apify login
179
138
  ```
180
139
 
140
+ Finally, we can easily deploy our code to the Apify platform by running:
141
+
181
142
  ```bash
182
143
  apify push
183
144
  ```
@@ -185,32 +146,18 @@ apify push
185
146
  Your script will be uploaded to the Apify platform and built there so that it can be run. For more information, view the
186
147
  [Apify Actor](https://docs.apify.com/cli) documentation.
187
148
 
188
- ### Usage on the Apify platform
189
-
190
- You can also develop your web scraping project in an online code editor directly on the [Apify platform](https://sdk.apify.com/docs/guides/apify-platform).
191
- 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>
192
- and then go to the <i>Source</i> tab and start writing your code or paste one of the examples from the Examples section.
149
+ You can also develop your web scraping project in an online code editor directly on the [Apify platform](https://apify.github.io/apify-ts/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.
193
150
 
194
151
  For more information, view the [Apify actors quick start guide](https://docs.apify.com/actor/quick-start).
195
152
 
196
153
  ## Support
197
154
 
198
- If you find any bug or issue with the Apify SDK, please [submit an issue on GitHub](https://github.com/apify/apify-js/issues).
199
- For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify) or contact support@apify.com
155
+ If you find any bug or issue with Crawlee, please [submit an issue on GitHub](https://github.com/apify/apify-ts/issues). For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify) or contact support@apify.com
200
156
 
201
157
  ## Contributing
202
158
 
203
- Your code contributions are welcome and you'll be praised to eternity!
204
- If you have any ideas for improvements, either submit an issue or create a pull request.
205
- For contribution guidelines and the code of conduct,
206
- see [CONTRIBUTING.md](https://github.com/apify/apify-js/blob/master/CONTRIBUTING.md).
159
+ 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](https://github.com/apify/apify-ts/blob/master/CONTRIBUTING.md).
207
160
 
208
161
  ## License
209
162
 
210
- This project is licensed under the Apache License 2.0 -
211
- see the [LICENSE.md](https://github.com/apify/apify-js/blob/master/LICENSE.md) file for details.
212
-
213
- ## Acknowledgments
214
-
215
- Many thanks to [Chema Balsas](https://www.npmjs.com/~jbalsas) for giving up the `apify` package name
216
- on NPM and renaming his project to [jsdocify](https://www.npmjs.com/package/jsdocify).
163
+ This project is licensed under the Apache License 2.0 - see the [LICENSE.md](https://github.com/apify/apify-ts/blob/master/LICENSE.md) file for details.