@crawlee/cheerio 3.3.4-beta.16 → 3.3.4-beta.17

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 (2) hide show
  1. package/README.md +107 -35
  2. package/package.json +18 -11
package/README.md CHANGED
@@ -1,55 +1,127 @@
1
- # `@crawlee/cheerio`
1
+ <h1 align="center">
2
+ <a href="https://crawlee.dev">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true">
5
+ <img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500">
6
+ </picture>
7
+ </a>
8
+ <br>
9
+ <small>A web scraping and browser automation library</small>
10
+ </h1>
2
11
 
3
- Provides a framework for the parallel crawling of web pages using plain HTTP requests and [cheerio](https://www.npmjs.com/package/cheerio) HTML parser. The URLs to crawl are fed either from a static list of URLs or from a dynamic queue of URLs enabling recursive crawling of websites.
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.svg" alt="NPM latest 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/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
+ </p>
4
18
 
5
- Since `CheerioCrawler` uses raw HTTP requests to download web pages, it is very fast and efficient on data bandwidth. However, if the target website requires JavaScript to display the content, you might need to use [PuppeteerCrawler](https://crawlee.dev/api/puppeteer-crawler/class/PuppeteerCrawler) or [PlaywrightCrawler](https://crawlee.dev/api/playwright-crawler/class/PlaywrightCrawler) instead, because it loads the pages using full-featured headless Chrome browser.
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. ℹ️
6
20
 
7
- `CheerioCrawler` downloads each URL using a plain HTTP request, parses the HTML content using [Cheerio](https://www.npmjs.com/package/cheerio) and then invokes the user-provided [CheerioCrawlerOptions.requestHandler](https://crawlee.dev/api/cheerio-crawler/interface/CheerioCrawlerOptions#requestHandler) to extract page data using a [jQuery](https://jquery.com/)-like interface to the parsed HTML DOM.
21
+ Crawlee covers your crawling and scraping end-to-end and **helps you build reliable scrapers. Fast.**
8
22
 
9
- The source URLs are represented using [Request](https://crawlee.dev/api/core/class/Request) objects that are fed from [RequestList](https://crawlee.dev/api/core/class/RequestList) or [RequestQueue](https://crawlee.dev/api/core/class/RequestQueue) instances provided by the [CheerioCrawlerOptions.requestList](https://crawlee.dev/api/cheerio-crawler/interface/CheerioCrawlerOptions#requestList) or [CheerioCrawlerOptions.requestQueue](https://crawlee.dev/api/cheerio-crawler/interface/CheerioCrawlerOptions#requestQueue) constructor options, respectively.
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.
10
24
 
11
- If both [CheerioCrawlerOptions.requestList](https://crawlee.dev/api/cheerio-crawler/interface/CheerioCrawlerOptions#requestList) and [CheerioCrawlerOptions.requestQueue](https://crawlee.dev/api/cheerio-crawler/interface/CheerioCrawlerOptions#requestQueue) are used, the instance first processes URLs from the [RequestList](https://crawlee.dev/api/core/class/RequestList) and automatically enqueues all of them to [RequestQueue](https://crawlee.dev/api/core/class/RequestQueue) before it starts their processing. This ensures that a single URL is not crawled multiple times.
25
+ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) NPM package.
12
26
 
13
- The crawler finishes when there are no more [Request](https://crawlee.dev/api/core/class/Request) objects to crawl.
27
+ > 👉 **View full documentation, guides and examples on the [Crawlee project website](https://crawlee.dev)** 👈
14
28
 
15
- We can use the `preNavigationHooks` to adjust `gotOptions`:
29
+ ## Installation
16
30
 
31
+ We recommend visiting the [Introduction tutorial](https://crawlee.dev/docs/introduction) in Crawlee documentation for more information.
32
+
33
+ > Crawlee requires **Node.js 16 or higher**.
34
+
35
+ ### With Crawlee CLI
36
+
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.
38
+
39
+ ```bash
40
+ npx crawlee create my-crawler
17
41
  ```
18
- preNavigationHooks: [
19
- (crawlingContext, gotOptions) => {
20
- // ...
21
- },
22
- ]
42
+
43
+ ```bash
44
+ cd my-crawler
45
+ npm start
23
46
  ```
24
47
 
25
- By default, `CheerioCrawler` only processes web pages with the `text/html` and `application/xhtml+xml` MIME content types (as reported by the `Content-Type` HTTP header), and skips pages with other content types. If you want the crawler to process other content types, use the [CheerioCrawlerOptions.additionalMimeTypes](https://crawlee.dev/api/cheerio-crawler/interface/CheerioCrawlerOptions#additionalMimeTypes) constructor option. Beware that the parsing behavior differs for HTML, XML, JSON and other types of content. For more details, see [CheerioCrawlerOptions.requestHandler](https://crawlee.dev/api/cheerio-crawler/interface/CheerioCrawlerOptions#requestHandler).
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.
26
50
 
27
- New requests are only dispatched when there is enough free CPU and memory available, using the functionality provided by the [AutoscaledPool](https://crawlee.dev/api/core/class/AutoscaledPool) class. All [AutoscaledPool](https://crawlee.dev/api/core/class/AutoscaledPool) configuration options can be passed to the `autoscaledPoolOptions` parameter of the `CheerioCrawler` constructor. For user convenience, the `minConcurrency` and `maxConcurrency` [AutoscaledPool](https://crawlee.dev/api/core/class/AutoscaledPool) options are available directly in the `CheerioCrawler` constructor.
51
+ ```bash
52
+ npm install crawlee playwright
53
+ ```
28
54
 
29
- ## Example usage
55
+ ```js
56
+ import { PlaywrightCrawler, Dataset } from 'crawlee';
30
57
 
31
- ```ts
32
- const crawler = new CheerioCrawler({
33
- requestList,
34
- async requestHandler({ request, response, body, contentType, $ }) {
35
- const data = [];
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}'`);
36
65
 
37
- // Do some data extraction from the page with Cheerio.
38
- $('.some-collection').each((index, el) => {
39
- data.push({ title: $(el).find('.some-title').text() });
40
- });
66
+ // Save results as JSON to ./storage/datasets/default
67
+ await Dataset.pushData({ title, url: request.loadedUrl });
41
68
 
42
- // Save the data to dataset.
43
- await Dataset.pushData({
44
- url: request.url,
45
- html: body,
46
- data,
47
- })
69
+ // Extract links from the current page
70
+ // and add them to the crawling queue.
71
+ await enqueueLinks();
48
72
  },
73
+ // Uncomment this option to see the browser window.
74
+ // headless: false,
49
75
  });
50
76
 
51
- await crawler.run([
52
- 'http://www.example.com/page-1',
53
- 'http://www.example.com/page-2',
54
- ]);
77
+ // Add first URL to the queue and start the crawl.
78
+ await crawler.run(['https://crawlee.dev']);
55
79
  ```
80
+
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).
82
+
83
+ ## 🛠 Features
84
+
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
95
+
96
+ ### 👾 HTTP crawling
97
+
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
103
+
104
+ ### 💻 Real browser crawling
105
+
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
112
+
113
+ ## Usage on the Apify platform
114
+
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.
116
+
117
+ ## Support
118
+
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).
120
+
121
+ ## Contributing
122
+
123
+ 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/crawlee/blob/master/CONTRIBUTING.md).
124
+
125
+ ## License
126
+
127
+ This project is licensed under the Apache License 2.0 - see the [LICENSE.md](https://github.com/apify/crawlee/blob/master/LICENSE.md) file for details.
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@crawlee/cheerio",
3
- "version": "3.3.4-beta.16",
3
+ "version": "3.3.4-beta.17",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
6
  "node": ">=16.0.0"
7
7
  },
8
- "main": "./dist/index.js",
9
- "module": "./dist/index.mjs",
10
- "types": "./dist/index.d.ts",
8
+ "main": "./index.js",
9
+ "module": "./index.mjs",
10
+ "types": "./index.d.ts",
11
11
  "exports": {
12
12
  ".": {
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
13
+ "import": "./index.mjs",
14
+ "require": "./index.js",
15
+ "types": "./index.d.ts"
16
16
  },
17
17
  "./package.json": "./package.json"
18
18
  },
@@ -46,18 +46,25 @@
46
46
  "scripts": {
47
47
  "build": "yarn clean && yarn compile && yarn copy",
48
48
  "clean": "rimraf ./dist",
49
- "compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./dist/index.js ./dist/index.mjs",
49
+ "compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./index.js ./index.mjs",
50
50
  "copy": "ts-node -T ../../scripts/copy.ts"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"
54
54
  },
55
55
  "dependencies": {
56
- "@crawlee/http": "^3.3.4-beta.16",
57
- "@crawlee/types": "^3.3.4-beta.16",
56
+ "@crawlee/http": "^3.3.4-beta.17",
57
+ "@crawlee/types": "^3.3.4-beta.17",
58
58
  "cheerio": "^1.0.0-rc.12",
59
59
  "htmlparser2": "^9.0.0",
60
60
  "tslib": "^2.4.0"
61
61
  },
62
- "gitHead": "67a826c104e2e29a65ff89ccabaecf8b078f2c98"
62
+ "lerna": {
63
+ "command": {
64
+ "publish": {
65
+ "assets": []
66
+ }
67
+ }
68
+ },
69
+ "gitHead": "8bbc596f4dba0aa755df204d836c97c05fc94fca"
63
70
  }