@crawlee/types 3.0.0-beta.1 → 3.0.0-beta.12
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 +50 -63
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- Mirror this part to src/index.js -->
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@crawlee/core)
|
|
6
|
+
[](https://www.npmjs.com/package/@crawlee/core)
|
|
7
7
|
[](https://discord.gg/jyEM2PRvMU)
|
|
8
|
-
[](https://github.com/apify/apify-ts/actions/workflows/test-and-release.yml)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Crawlee simplifies the development of web crawlers, scrapers, data extractors and web automation jobs.
|
|
11
11
|
It provides tools to manage and automatically scale a pool of headless browsers,
|
|
12
12
|
to maintain queues of URLs to crawl, store crawling results to a local filesystem or into the cloud,
|
|
13
13
|
rotate proxies and much more.
|
|
14
|
-
The SDK is available as the [`
|
|
14
|
+
The SDK is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) NPM package.
|
|
15
15
|
It can be used either stand-alone in your own applications
|
|
16
16
|
or in [actors](https://docs.apify.com/actor)
|
|
17
17
|
running on the [Apify Cloud](https://apify.com/).
|
|
18
18
|
|
|
19
|
-
**View full documentation, guides and examples on the [
|
|
19
|
+
**View full documentation, guides and examples on the [Crawlee project website](https://apify.github.io/apify-ts/)**
|
|
20
20
|
|
|
21
|
-
> Would you like to work with us on
|
|
21
|
+
> Would you like to work with us on Crawlee or similar projects? [We are hiring!](https://apify.com/jobs#senior-node.js-engineer)
|
|
22
22
|
|
|
23
23
|
## Motivation
|
|
24
24
|
|
|
@@ -35,119 +35,106 @@ Python has [Scrapy](https://scrapy.org/) for these tasks, but there was no such
|
|
|
35
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
36
|
browser.
|
|
37
37
|
|
|
38
|
-
The goal of
|
|
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
|
|
39
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
40
|
commonalities.
|
|
41
41
|
|
|
42
42
|
## Overview
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
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
45
|
|
|
46
|
-
|
|
46
|
+
[//]: # (TODO add links to the docs about `@crawlee/` packages and the `crawlee` metapackage)
|
|
47
|
+
|
|
48
|
+
- [`CheerioCrawler`](https://apify.github.io/apify-ts/api/cheerio-crawler/class/CheerioCrawler) - Enables the parallel crawling of a large
|
|
47
49
|
number of web pages using the [cheerio](https://www.npmjs.com/package/cheerio) HTML parser. This is the most
|
|
48
50
|
efficient web crawler, but it does not work on websites that require JavaScript.
|
|
49
51
|
|
|
50
|
-
- [`PuppeteerCrawler`](https://
|
|
52
|
+
- [`PuppeteerCrawler`](https://apify.github.io/apify-ts/api/puppeteer-crawler/class/PuppeteerCrawler) - Enables the parallel crawling of
|
|
51
53
|
a large number of web pages using the headless Chrome browser and [Puppeteer](https://github.com/puppeteer/puppeteer).
|
|
52
54
|
The pool of Chrome browsers is automatically scaled up and down based on available system resources.
|
|
53
55
|
|
|
54
|
-
- [`PlaywrightCrawler`](https://
|
|
56
|
+
- [`PlaywrightCrawler`](https://apify.github.io/apify-ts/api/playwright-crawler/class/PlaywrightCrawler) - Unlike `PuppeteerCrawler`
|
|
55
57
|
you can use [Playwright](https://github.com/microsoft/playwright) to manage almost any headless browser.
|
|
56
58
|
It also provides a cleaner and more mature interface while keeping the ease of use and advanced features.
|
|
57
59
|
|
|
58
|
-
- [`BasicCrawler`](https://
|
|
60
|
+
- [`BasicCrawler`](https://apify.github.io/apify-ts/api/basic-crawler/class/BasicCrawler) - Provides a simple framework for the parallel
|
|
59
61
|
crawling of web pages whose URLs are fed either from a static list or from a dynamic queue of URLs. This class
|
|
60
62
|
serves as a base for the more specialized crawlers above.
|
|
61
63
|
|
|
62
|
-
- [`RequestList`](https://
|
|
64
|
+
- [`RequestList`](https://apify.github.io/apify-ts/api/core/class/RequestList) - Represents a list of URLs to crawl.
|
|
63
65
|
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
66
|
can resume when the Node.js process restarts.
|
|
65
67
|
|
|
66
|
-
- [`RequestQueue`](https://
|
|
68
|
+
- [`RequestQueue`](https://apify.github.io/apify-ts/api/core/class/RequestQueue) - Represents a queue of URLs to crawl,
|
|
67
69
|
which is stored either on a local filesystem or in the [Apify Cloud](https://apify.com). The queue is used
|
|
68
70
|
for deep crawling of websites, where you start with several URLs and then recursively follow links to other pages.
|
|
69
71
|
The data structure supports both breadth-first and depth-first crawling orders.
|
|
70
72
|
|
|
71
|
-
- [`Dataset`](https://
|
|
73
|
+
- [`Dataset`](https://apify.github.io/apify-ts/api/core/class/Dataset) - Provides a store for structured data and enables their export
|
|
72
74
|
to formats like JSON, JSONL, CSV, XML, Excel or HTML. The data is stored on a local filesystem or in the Apify Cloud.
|
|
73
75
|
Datasets are useful for storing and sharing large tabular crawling results, such as a list of products or real estate offers.
|
|
74
76
|
|
|
75
|
-
- [`KeyValueStore`](https://
|
|
77
|
+
- [`KeyValueStore`](https://apify.github.io/apify-ts/api/core/class/KeyValueStore) - A simple key-value store for arbitrary data
|
|
76
78
|
records or files, along with their MIME content type. It is ideal for saving screenshots of web pages, PDFs
|
|
77
79
|
or to persist the state of your crawlers. The data is stored on a local filesystem or in the Apify Cloud.
|
|
78
80
|
|
|
79
|
-
- [`AutoscaledPool`](https://
|
|
81
|
+
- [`AutoscaledPool`](https://apify.github.io/apify-ts/api/core/class/AutoscaledPool) - Runs asynchronous background tasks,
|
|
80
82
|
while automatically adjusting the concurrency based on free system memory and CPU usage. This is useful for running
|
|
81
83
|
web scraping tasks at the maximum capacity of the system.
|
|
82
84
|
|
|
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
85
|
Additionally, the package provides various helper functions to simplify running your code on the Apify Cloud and thus
|
|
87
86
|
take advantage of its pool of proxies, job scheduler, data storage, etc.
|
|
88
|
-
For more information, see the [
|
|
87
|
+
For more information, see the [Crawlee Programmer's Reference](https://apify.github.io/apify-ts/).
|
|
89
88
|
|
|
90
89
|
## Quick Start
|
|
91
90
|
|
|
92
|
-
This short tutorial will set you up to start using
|
|
93
|
-
If you want to learn more, proceed to the [Getting Started](https://
|
|
91
|
+
This short tutorial will set you up to start using Crawlee in a minute or two.
|
|
92
|
+
If you want to learn more, proceed to the [Getting Started](https://apify.github.io/apify-ts/docs/guides/getting-started)
|
|
94
93
|
tutorial that will take you step by step through creating your first scraper.
|
|
95
94
|
|
|
96
95
|
### Local stand-alone usage
|
|
97
96
|
|
|
98
|
-
|
|
99
|
-
Add
|
|
97
|
+
Crawlee requires [Node.js](https://nodejs.org/en/) 16 or later.
|
|
98
|
+
Add Crawlee to any Node.js project by running:
|
|
100
99
|
|
|
101
100
|
```bash
|
|
102
|
-
npm install
|
|
101
|
+
npm install @crawlee/playwright playwright
|
|
103
102
|
```
|
|
104
103
|
|
|
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.
|
|
104
|
+
> Neither `playwright` nor `puppeteer` are bundled with the SDK to reduce install size and allow greater flexibility. That's why we install it with NPM. You can choose one, both, or neither.
|
|
107
105
|
|
|
108
|
-
Run the following example to perform a recursive crawl of a website using Playwright. For more examples showcasing various features of
|
|
109
|
-
[see the Examples section of the documentation](https://
|
|
106
|
+
Run the following example to perform a recursive crawl of a website using Playwright. For more examples showcasing various features of Crawlee,
|
|
107
|
+
[see the Examples section of the documentation](https://apify.github.io/apify-ts/docs/examples/crawl-multiple-urls).
|
|
110
108
|
|
|
111
109
|
```javascript
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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();
|
|
110
|
+
import { PlaywrightCrawler } from '@crawlee/playwright';
|
|
111
|
+
|
|
112
|
+
const crawler = new PlaywrightCrawler({
|
|
113
|
+
async requestHandler({ request, page, enqueueLinks }) {
|
|
114
|
+
// Extract HTML title of the page.
|
|
115
|
+
const title = await page.title();
|
|
116
|
+
console.log(`Title of ${request.url}: ${title}`);
|
|
117
|
+
|
|
118
|
+
// Add URLs from the same subdomain.
|
|
119
|
+
await enqueueLinks();
|
|
120
|
+
},
|
|
137
121
|
});
|
|
122
|
+
|
|
123
|
+
// Choose the first URL to open and run the crawler.
|
|
124
|
+
await crawler.addRequests(['https://www.iana.org/']);
|
|
125
|
+
await crawler.run();
|
|
138
126
|
```
|
|
139
127
|
|
|
140
|
-
When you run the example, you should see
|
|
128
|
+
When you run the example, you should see Crawlee automating a Chrome browser.
|
|
141
129
|
|
|
142
|
-

|
|
143
131
|
|
|
144
|
-
By default,
|
|
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).
|
|
132
|
+
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
133
|
|
|
147
134
|
### Local usage with Apify command-line interface (CLI)
|
|
148
135
|
|
|
149
136
|
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://
|
|
137
|
+
the [Apify platform](https://apify.github.io/apify-ts/docs/guides/apify-platform), you can use the [Apify command-line interface (CLI)](https://github.com/apify/apify-cli) tool.
|
|
151
138
|
|
|
152
139
|
Install the CLI by running:
|
|
153
140
|
|
|
@@ -187,7 +174,7 @@ Your script will be uploaded to the Apify platform and built there so that it ca
|
|
|
187
174
|
|
|
188
175
|
### Usage on the Apify platform
|
|
189
176
|
|
|
190
|
-
You can also develop your web scraping project in an online code editor directly on the [Apify platform](https://
|
|
177
|
+
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).
|
|
191
178
|
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
179
|
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
180
|
|
|
@@ -195,7 +182,7 @@ For more information, view the [Apify actors quick start guide](https://docs.api
|
|
|
195
182
|
|
|
196
183
|
## Support
|
|
197
184
|
|
|
198
|
-
If you find any bug or issue with
|
|
185
|
+
If you find any bug or issue with Crawlee, please [submit an issue on GitHub](https://github.com/apify/apify-js/issues).
|
|
199
186
|
For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify) or contact support@apify.com
|
|
200
187
|
|
|
201
188
|
## Contributing
|