Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Update readme
Ondra Urban362f3df84368
diff --git a/README.md b/README.mdindex e575b7100..5fb93dd73 100644--- a/README.md+++ b/README.md@@ -3,10 +3,6 @@<!-- Mirror this part to src/index.js -->[](https://www.npmjs.com/package/apify)-[](https://travis-ci.com/apify/apify-js)--> This README is for the soon to be relased Apify SDK v1.0.0. [Find the 0.22.x README here](https://github.com/apify/apify-js/tree/v0.22.3).-> You can try the beta of SDK v1 by installing `apify@beta`.Apify SDK 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,@@ -17,11 +13,11 @@ It can be used either stand-alone in your own applicationsor in [actors](https://docs.apify.com/actor)running on the [Apify Cloud](https://apify.com/).-**View full documentation, guides and examples on the dedicated [Apify SDK project website](https://sdk.apify.com)**+**View full documentation, guides and examples on the [Apify SDK project website](https://sdk.apify.com)**## Motivation-Thanks to tools like [Puppeteer](https://github.com/puppeteer/puppeteer), [Playwright](https://github.com/microsoft/playwright) or+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. Buteventually things will get complicated. For example, when you try to:@@ -42,48 +38,49 @@ commonalities.The Apify SDK is available as the [`apify`](https://www.npmjs.com/package/apify) NPM package and it provides the following tools:-- [`BasicCrawler`](https://sdk.apify.com/docs/api/basic-crawler) - 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 more complex crawlers (see below).-- [`CheerioCrawler`](https://sdk.apify.com/docs/api/cheerio-crawler) - 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.+ 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.- [`PuppeteerCrawler`](https://sdk.apify.com/docs/api/puppeteer-crawler) - 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.+ 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.- [`PlaywrightCrawler`](https://sdk.apify.com/docs/api/playwright-crawler) - 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.+ 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.++- [`BasicCrawler`](https://sdk.apify.com/docs/api/basic-crawler) - 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.- [`RequestList`](https://sdk.apify.com/docs/api/request-list) - 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.+ 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.- [`RequestQueue`](https://sdk.apify.com/docs/api/request-queue) - Represents a queue of URLs to crawl,-which is stored either 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.+ which is stored either 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.- [`Dataset`](https://sdk.apify.com/docs/api/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.+ 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.- [`KeyValueStore`](https://sdk.apify.com/docs/api/key-value-store) - 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.+ 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.- [`AutoscaledPool`](https://sdk.apify.com/docs/api/autoscaled-pool) - 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.+ 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.++- [`Browser Utils`](https://sdk.apify.com/docs/api/puppeteer) - Provides several helper functions useful+ for web scraping. For example, to inject jQuery into web pages or to hide browser origin.-- [`Puppeteer Utils`](https://sdk.apify.com/docs/api/puppeteer) - Provides several helper functions useful-for web scraping. For example, to inject jQuery into web pages or to hide browser origin. 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 [Apify SDK Programmer's Reference](https://sdk.apify.com).+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 [Apify SDK Programmer's Reference](https://sdk.apify.com).## Quick Start@@ -145,7 +142,7 @@ By default, Apify SDK stores data to `./apify_storage` in the current working di### Local usage with Apify command-line interface (CLI)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-the [Apify platform](/docs/guides/apify-platform), you can use the [Apify command-line interface (CLI)](https://github.com/apify/apify-cli) tool.+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.Install the CLI by running:diff --git a/docs/guides/motivation.md b/docs/guides/motivation.mdindex e19dd604d..9a3290be3 100644--- a/docs/guides/motivation.md+++ b/docs/guides/motivation.md@@ -3,7 +3,7 @@ id: motivationtitle: Motivation----Thanks to tools like [Puppeteer](https://github.com/puppeteer/puppeteer) or+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. Buteventually things will get complicated. For example, when you try to:diff --git a/docs/guides/quick_start.md b/docs/guides/quick_start.mdindex 5d18a5b1d..7aee2a0dc 100644--- a/docs/guides/quick_start.md+++ b/docs/guides/quick_start.md@@ -12,34 +12,38 @@ Apify SDK requires [Node.js](https://nodejs.org/en/) 10.17 or later, with the exAdd Apify SDK to any Node.js project by running:```bash-npm install apify --save+npm install apify playwright```-Run the following example to perform a recursive crawl of a website using Puppeteer. For more examples showcasing various features of the Apify SDK,-[see the Examples section of the documentation](../examples/basic-crawler).+> 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.++Run the following example to perform a recursive crawl of a website using Playwright. For more examples showcasing various features of the Apify SDK,+[see the Examples section of the documentation](../examples/crawl-multiple-urls).```javascriptconst Apify = require('apify');+// Apify.main is a helper function, you don't need to use it.Apify.main(async () => {const requestQueue = await Apify.openRequestQueue();+ // Choose the first URL to open.await requestQueue.addRequest({ url: 'https://www.iana.org/' });- const pseudoUrls = [new Apify.PseudoUrl('https://www.iana.org/[.*]')];- const crawler = new Apify.PuppeteerCrawler({+ const crawler = new Apify.PlaywrightCrawler({requestQueue,handlePageFunction: async ({ request, page }) => {+ // Extract HTML title of the page.const title = await page.title();console.log(`Title of ${request.url}: ${title}`);++ // Add URLs that match the provided pattern.await Apify.utils.enqueueLinks({page,- selector: 'a',- pseudoUrls,requestQueue,+ pseudoUrls: ['https://www.iana.org/[.*]'],});},- maxRequestsPerCrawl: 100,- maxConcurrency: 10,});await crawler.run();@@ -65,8 +69,6 @@ Install the CLI by running:npm -g install apify-cli```-You might need to run the above command with `sudo`, depending on how crazy your configuration is.-Now create a boilerplate of your new web crawling project by running:```bashdiff --git a/docs/readme/introduction.md b/docs/readme/introduction.mdindex 5156de2a1..87baa2b46 100644--- a/docs/readme/introduction.md+++ b/docs/readme/introduction.md@@ -3,10 +3,9 @@<!-- Mirror this part to src/index.js -->[](https://www.npmjs.com/package/apify)-[](https://travis-ci.org/apifytech/apify-js)Apify SDK 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 Chrome / Puppeteer instances,+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.The SDK is available as the [`apify`](https://www.npmjs.com/package/apify) NPM package.@@ -14,4 +13,4 @@ It can be used either stand-alone in your own applicationsor in [actors](https://docs.apify.com/actor)running on the [Apify Cloud](https://apify.com/).-**View full documentation, guides and examples on the dedicated [Apify SDK project website](https://sdk.apify.com)**+**View full documentation, guides and examples on the [Apify SDK project website](https://sdk.apify.com)**diff --git a/docs/readme/overview.md b/docs/readme/overview.mdindex c1939a296..dc56fd26d 100644--- a/docs/readme/overview.md+++ b/docs/readme/overview.md@@ -2,45 +2,46 @@The Apify SDK is available as the [`apify`](https://www.npmjs.com/package/apify) NPM package and it provides the following tools:-- [`BasicCrawler`](https://sdk.apify.com/docs/api/basic-crawler) - 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 more complex crawlers (see below).-- [`CheerioCrawler`](https://sdk.apify.com/docs/api/cheerio-crawler) - 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.+ 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.- [`PuppeteerCrawler`](https://sdk.apify.com/docs/api/puppeteer-crawler) - 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.+ 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.++- [`PlaywrightCrawler`](https://sdk.apify.com/docs/api/playwright-crawler) - 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.-- [`PuppeteerPool`](https://sdk.apify.com/docs/api/puppeteer-pool) - Provides web browser tabs for user jobs-from an automatically-managed pool of Chrome browser instances, with configurable browser recycling-and retirement policies. Supports reuse of the disk cache to speed up the crawling of websites and reduce proxy bandwidth.+- [`BasicCrawler`](https://sdk.apify.com/docs/api/basic-crawler) - 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.- [`RequestList`](https://sdk.apify.com/docs/api/request-list) - 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.+ 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.- [`RequestQueue`](https://sdk.apify.com/docs/api/request-queue) - Represents a queue of URLs to crawl,-which is stored either 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.+ which is stored either 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.- [`Dataset`](https://sdk.apify.com/docs/api/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.+ 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.- [`KeyValueStore`](https://sdk.apify.com/docs/api/key-value-store) - 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.+ 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.- [`AutoscaledPool`](https://sdk.apify.com/docs/api/autoscaled-pool) - 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.--- [`Puppeteer Utils`](https://sdk.apify.com/docs/api/puppeteer) - Provides several helper functions useful-for web scraping. For example, to inject jQuery into web pages or to hide browser origin. 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 [Apify SDK Programmer's Reference](https://sdk.apify.com).+ 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.++- [`Browser Utils`](https://sdk.apify.com/docs/api/puppeteer) - Provides several helper functions useful+ for web scraping. For example, to inject jQuery into web pages or to hide browser origin.++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 [Apify SDK Programmer's Reference](https://sdk.apify.com).diff --git a/package.json b/package.jsonindex 1ffa62729..65fde5241 100644--- a/package.json+++ b/package.json@@ -53,7 +53,7 @@"dependencies": {"@apify/http-request": "^2.1.1","@apify/ps-tree": "^1.1.3",- "@apify/storage-local": "^1.0.2",+ "@apify/storage-local": "^1.0.3","@types/cheerio": "^0.22.22","@types/domhandler": "^2.4.1","@types/node": "^14",diff --git a/tools/build_readme.js b/tools/build_readme.jsindex f366434e1..f9c5a8c43 100644--- a/tools/build_readme.js+++ b/tools/build_readme.js@@ -19,9 +19,9 @@ const hashReplace = '### ';const fixHeaders = doc => doc.replace(hashRx, hashReplace).replace(headerRx, headerReplace);-const linkRx = /\[(.*)]\((.*)\)/g;+const linkRx = /\[(.*?)]\((.*?)\)/g;const fixLinks = (match, p1, p2) => {- const url = new URL(p2, 'https://sdk.apify.com/docs/');+ const url = new URL(p2, 'https://sdk.apify.com/docs/something/'); // <- the links use ../ so we need something to go up fromreturn `[${p1}](${url})`;};