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
docs: introduction rewrites (#2340)
TCMO3f9c7a9fd5f2
diff --git a/docs/introduction/01-setting-up.mdx b/docs/introduction/01-setting-up.mdxindex a69852298..b1b131dab 100644--- a/docs/introduction/01-setting-up.mdx+++ b/docs/introduction/01-setting-up.mdx@@ -10,10 +10,8 @@ import ApiLink from '@site/src/components/ApiLink';To run Crawlee on your own computer, you need to meet the following pre-requisites first:-1. Have **Node.js version 16.0** or higher installed.- - Visit [Node.js website](https://nodejs.org/en/download/) to download or use [fnm](https://github.com/Schniz/fnm)+1. Have **Node.js version 16.0** (Visit [Node.js website](https://nodejs.org/en/download/) to download or use [fnm](https://github.com/Schniz/fnm)) or higher installed.2. Have **NPM** installed, or use other package manager of your choice.- - NPM comes bundled with Node.js, so you should already have it. If not, reinstall Node.js.If not certain, confirm the prerequisites by running:@@ -33,7 +31,7 @@ The fastest and best way to create new projects with Crawlee is to use the [Crawnpx crawlee create my-crawler```-A prompt will be shown, asking you to choose a template. Crawlee is written in TypeScript so if you're familiar with it, choosing a TypeScript template will give you better code completion and static type checking, but feel free to use JavaScript as well. Functionally they're identical.+A prompt will be shown, asking you to select a template. Crawlee is written in TypeScript so if you're familiar with it, choosing a TypeScript template will give you better code completion and static type checking, but feel free to use JavaScript as well. Functionally they're identical.Let's choose the first template called **Getting started example**. The command will create a new directory in your current working directory, called **my-crawler**, add a **package.json** to this folder and install all the necessary dependencies. It will also add example source code that you can immediately run.@@ -65,7 +63,6 @@ CTRL+CBrowsers controlled by Playwright run headless (without a visible window). You can switch to headful by uncommenting the `headless: false` option in the crawler's constructor. This is useful in the development phase when you want to see what's going on in the browser.-```typescript// Uncomment this option to see the browser window.headless: false@@ -87,6 +84,6 @@ For the sake of this show off, we've slowed down the crawler, but rest assured,}}/>-## Next lesson+## Next steps-The next lesson will teach you how to create a very simple crawler and explain Crawlee components while building it.+Next, you will see how to create a very simple crawler and explain Crawlee components while building it.diff --git a/docs/introduction/02-first-crawler.mdx b/docs/introduction/02-first-crawler.mdxindex fd36ebedd..92ddaef74 100644--- a/docs/introduction/02-first-crawler.mdx+++ b/docs/introduction/02-first-crawler.mdx@@ -6,13 +6,19 @@ description: Your first steps into the world of scraping with Crawleeimport ApiLink from '@site/src/components/ApiLink';-In this lesson, you will build your first crawler. But before you do, let's briefly introduce the Crawlee classes involved in the process.+Now, you will build your first crawler. But before you do, let's briefly introduce the Crawlee classes involved in the process.## How Crawlee works-There are 3 main crawler classes available for use in Crawlee. <ApiLink to="cheerio-crawler/class/CheerioCrawler">`CheerioCrawler`</ApiLink>, <ApiLink to="puppeteer-crawler/class/PuppeteerCrawler">`PuppeteerCrawler`</ApiLink> and <ApiLink to="playwright-crawler/class/PlaywrightCrawler">`PlaywrightCrawler`</ApiLink>. We'll talk about their differences later. Now, let's talk about what they have in common.+There are 3 main crawler classes available for use in Crawlee.-The general idea of each crawler is to go to a web page, open it, do some stuff there, save some results, continue to the next page, and repeat this process until the crawler's done its job. So the crawler always needs to find answers to two questions: **Where should I go?** and **What should I do there?** Answering those two questions is the only required setup. The crawlers have reasonable defaults for everything else.+- <ApiLink to="cheerio-crawler/class/CheerioCrawler">`CheerioCrawler`</ApiLink>+- <ApiLink to="puppeteer-crawler/class/PuppeteerCrawler">`PuppeteerCrawler`</ApiLink>+- <ApiLink to="playwright-crawler/class/PlaywrightCrawler">`PlaywrightCrawler`</ApiLink>++We'll talk about their differences later. Now, let's talk about what they have in common.++The general idea of each crawler is to go to a web page, open it, do some stuff there, save some results, continue to the next page, and repeat this process until the crawler's done its job. So the crawler always needs to find answers to two questions: _Where should I go?_ and _What should I do there?_ Answering those two questions is the only required setup. The crawlers have reasonable defaults for everything else.### The Where - `Request` and `RequestQueue`@@ -30,7 +36,7 @@ The `requestHandler` is a user-defined function, invoked automatically by the crLet's put the theory into practice and start with something easy. Visit a page and get its HTML title. In this tutorial, you'll scrape the Crawlee website [https://crawlee.dev](https://crawlee.dev), but the same code will work for any website.-:::info+:::info Top level await configurationWe are using a JavaScript feature called [Top level await](https://blog.saeloun.com/2021/11/25/ecmascript-top-level-await.html) in our examples. To be able to use that, you might need some extra setup. Namely, it requires the use of [ECMAScript Modules](https://nodejs.org/api/esm.html) - this means you either need to add `"type": "module"` to your `package.json` file, or use `*.mjs` extension for your files. Additionally, if you are in a TypeScript project, you need to set the `module` and `target` compiler options to `ES2022` or above.@@ -51,7 +57,7 @@ await requestQueue.addRequest({ url: 'https://crawlee.dev' });The <ApiLink to="core/class/RequestQueue#addRequest">`requestQueue.addRequest()`</ApiLink> function automatically converts the object with URL string to a <ApiLink to="core/class/Request">`Request`</ApiLink> instance. So now you have a `requestQueue` that holds one request which points to `https://crawlee.dev`.-:::tip+:::tip Bulk add requestsThe code above is for illustration of the request queue concept. Soon you'll learn about the `crawler.addRequests()` method which allows you to skip this initialization code, and it also supports adding a large number of requests without blocking.@@ -117,5 +123,6 @@ await crawler.run(['https://crawlee.dev']);When you run this code, you'll see exactly the same output as with the earlier, longer example. The `RequestQueue` is still there, it's just managed by the crawler automatically.-## Next lesson-In the next lesson you'll learn about crawling links. That means finding new URLs on the pages you crawl and adding them to the `RequestQueue` for the crawler to visit.+## Next steps++Next, you'll learn about crawling links. That means finding new URLs on the pages you crawl and adding them to the `RequestQueue` for the crawler to visit.diff --git a/docs/introduction/03-adding-urls.mdx b/docs/introduction/03-adding-urls.mdxindex 52f2a99f0..21e6e58b0 100644--- a/docs/introduction/03-adding-urls.mdx+++ b/docs/introduction/03-adding-urls.mdx@@ -15,8 +15,8 @@ import FilterWithELSource from '!!raw-loader!./03-filter-el.ts';import FindWithoutELSource from '!!raw-loader!./03-find-without-el.ts';import FilterWithoutELSource from '!!raw-loader!./03-filter-without-el.ts';-In the previous lesson you built a very simple crawler that downloads HTML of a single page, reads its title and prints-it to the console. This is the original source code:+Previously you've built a very simple crawler that downloads HTML of a single page, reads its title and prints it to the console.+This is the original source code:```tsimport { CheerioCrawler } from 'crawlee';@@ -31,7 +31,7 @@ const crawler = new CheerioCrawler({await crawler.run(['https://crawlee.dev']);```-In this lesson you'll use the example from the previous section and improve on it. You'll add more URLs to the queue and thanks to that the crawler will keep going, finding new links, enqueuing them into the `RequestQueue` and then scraping them.+Now you'll use the example from the previous section and improve on it. You'll add more URLs to the queue and thanks to that the crawler will keep going, finding new links, enqueuing them into the `RequestQueue` and then scraping them.## How crawling works@@ -45,7 +45,7 @@ The process is simple:In the following paragraphs you will learn about the <ApiLink to="core/function/enqueueLinks">`enqueueLinks`</ApiLink> function which simplifies crawling to a single function call. For comparison and learning purposes we will show an equivalent solution written without `enqueueLinks` in the second code tab.-:::tip+:::tip `enqueueLinks` context awarenessThe `enqueueLinks` function is context aware. It means that it will read the information about the currently crawled page from the context, and you don't need to explicitly provide any arguments. It will find the links using the Cheerio function `$` and automatically add the links to the running crawler's `RequestQueue`.@@ -64,7 +64,6 @@ const crawler = new CheerioCrawler({This means that no new requests will be started after the 20th request is finished. The actual number of processed requests might be a little higher thanks to parallelization, because the running requests won't be forcefully aborted. It's not even possible in most cases.-## Finding new linksThere are numerous approaches to finding links to follow when crawling the web. For our purposes, we will be looking for `<a>` elements that contain the `href` attribute because that's what you need in most cases. For example:@@ -121,7 +120,7 @@ Skipping of duplicate URLs is critical, because visiting the same page multiple## Advanced filtering arguments-While the defaults for `enqueueLinks` can be often exactly what you need, it also gives you fine-grained control over which URLs should be enqueued. One way we already mentioned above is by using the <ApiLink to="core/enum/EnqueueStrategy">`EnqueueStrategy`</ApiLink>. You can use the <ApiLink to="core/enum/EnqueueStrategy#All">`All`</ApiLink> strategy if you want to follow every single link, regardless of its domain, or you can enqueue links that target the same domain name with the <ApiLink to="core/enum/EnqueueStrategy#SameDomain">`SameDomain`</ApiLink> strategy.+While the defaults for `enqueueLinks` can be often exactly what you need, it also gives you fine-grained control over which URLs should be enqueued. One way we already mentioned above. It is using the <ApiLink to="core/enum/EnqueueStrategy">`EnqueueStrategy`</ApiLink>. You can use the <ApiLink to="core/enum/EnqueueStrategy#All">`All`</ApiLink> strategy if you want to follow every single link, regardless of its domain, or you can enqueue links that target the same domain name with the <ApiLink to="core/enum/EnqueueStrategy#SameDomain">`SameDomain`</ApiLink> strategy.```tsawait enqueueLinks({@@ -133,7 +132,7 @@ await enqueueLinks({For even more control, you can use `globs`, `regexps` and `pseudoUrls` to filter the URLs. Each of those arguments is always an `Array`, but the contents can take on many forms. <ApiLink to="core/interface/EnqueueLinksOptions">See the reference</ApiLink> for more information about them as well as other options.-:::caution+:::caution Defaults overrideIf you provide one of those options, the default `same-hostname` strategy will **not** be applied unless explicitly set in the options.@@ -162,6 +161,6 @@ await enqueueLinks({And that's it! `enqueueLinks()` is just one example of Crawlee's powerful helper functions. They're all designed to make your life easier, so you can focus on getting your data, while leaving the mundane crawling management to the tools.-## Next lesson+## Next steps-In the next lesson you will start your project of scraping a production website and learn some more Crawlee tricks in the process.+Next, you will start your project of scraping a production website and learn some more Crawlee tricks in the process.diff --git a/docs/introduction/04-real-world-project.mdx b/docs/introduction/04-real-world-project.mdxindex d0c0c893b..3ff078a02 100644--- a/docs/introduction/04-real-world-project.mdx+++ b/docs/introduction/04-real-world-project.mdx@@ -23,9 +23,9 @@ Making a production-grade crawler is not difficult, but there are many pitfallsThe website requires JavaScript rendering, which allows us to showcase more features of Crawlee. We've also added some helpful tips that prepare you for the real-world issues that you will surely encounter when scraping at scale.-:::tip+:::tip Not interested in theory?-If you're not interested in crawling theory, feel free to [skip to the next lesson](./crawling) and get right back to coding.+If you're not interested in crawling theory, feel free to [skip to the next chapter](./crawling) and get right back to coding.:::@@ -33,11 +33,11 @@ If you're not interested in crawling theory, feel free to [skip to the next lessSometimes scraping is really straightforward, but most of the time, it really pays off to do a bit of research first and try to answer some of these questions:-- How is the website structured?-- Can I scrape it only with HTTP requests (read "with `CheerioCrawler`")?-- Do I need a headless browser for something?-- Are there any anti-scraping protections in place?-- Do I need to parse the HTML or can I get the data otherwise, such as directly from the website's API?+- How is the website structured?+- Can I scrape it only with HTTP requests (read "with `CheerioCrawler`")?+- Do I need a headless browser for something?+- Are there any anti-scraping protections in place?+- Do I need to parse the HTML or can I get the data otherwise, such as directly from the website's API?For the purposes of this tutorial, let's assume that the website cannot be scraped with `CheerioCrawler`. It actually can, but we would have to dive a bit deeper than this introductory guide allows. So for now we will make things easier for you, scrape it with `PlaywrightCrawler`, and you'll learn about headless browsers in the process.@@ -45,12 +45,12 @@ For the purposes of this tutorial, let's assume that the website cannot be scrapA good first step is to figure out what data you want to scrape and where to find it. For the time being, let's just agree that we want to scrape all products from all categories available on the [All collections page of the store](https://warehouse-theme-metal.myshopify.com/collections) and for each product we want to get its:-- URL-- Manufacturer-- SKU-- Title-- Current price-- Stock available+- URL+- Manufacturer+- SKU+- Title+- Current price+- Stock availableYou will notice that some information is available directly on the list page, but for details such as "SKU" we'll also need to open the product's detail page.@@ -68,7 +68,7 @@ Let's take a look at the `https://warehouse-theme-metal.myshopify.com/collectionWhen you click the categories, you'll see that they load a page of products filtered by that category. By going through a few categories and observing the behavior, we can also observe that we can sort by different conditions (such as `Best selling`, or `Price, low to high`), but for this example, we will not be looking into those.-:::caution+:::caution Limited paginationBe careful, because on some websites, like [amazon.com](https://amazon.com), this is not true and the sum of products in categories is actually larger than what's available without filters. Learn more in our [tutorial on scraping websites with limited pagination](https://docs.apify.com/tutorials/scrape-paginated-sites).@@ -78,13 +78,13 @@ Be careful, because on some websites, like [amazon.com](https://amazon.com), thiThe pagination of the demo Warehouse Store is simple enough. When switching between pages, you will see that the URL changes to:-```+```texthttps://warehouse-theme-metal.myshopify.com/collections/headphones?page=2```Try clicking on the link to page 4. You'll see that the pagination links update and show more pages. But can you trust that this will include all pages and won't stop at some point?-:::caution+:::caution Test your assumptionsSimilarly to the issue with filters explained above, the existence of pagination does not guarantee that you can simply paginate through all the results. Always test your assumptions about pagination. Otherwise, you might miss a chunk of results, and not even know about it.@@ -132,7 +132,7 @@ If you're wondering how to get that `.collection-block-item` selector. We'll exp## DevTools - the scraper's toolbox-:::info+:::info DevTool choiceWe'll use Chrome DevTools here, since it's the most common browser, but feel free to use any other, they're all very similar.@@ -162,12 +162,12 @@ document.querySelectorAll('.collection-block-item');You will see that only the 31 collection cards will be returned, and nothing else.-:::tip+:::tip Learn more about CSS selectors and DevToolsCSS selectors and DevTools are quite a big topic. If you want to learn more, visit the [Web scraping for beginners course](https://developers.apify.com/academy/web-scraping-for-beginners) in the Apify Academy. **It's free and open-source** ❤️.:::-## Next lesson+## Next steps-In the next lesson, we will crawl the whole store, including all the listing pages and all the product detail pages.+Next, you will crawl the whole store, including all the listing pages and all the product detail pages.diff --git a/docs/introduction/05-crawling.mdx b/docs/introduction/05-crawling.mdxindex a646699e5..6621ee10b 100644--- a/docs/introduction/05-crawling.mdx+++ b/docs/introduction/05-crawling.mdx@@ -97,6 +97,6 @@ await crawler.run(['https://warehouse-theme-metal.myshopify.com/collections']);The crawling code is now complete. When you run the code, you'll see the crawler visit all the listing URLs and all the detail URLs.-## Next lesson+## Next stepsThis concludes the Crawling lesson, because you have taught the crawler to visit all the pages it needs. Let's continue with scraping data.diff --git a/docs/introduction/06-scraping.mdx b/docs/introduction/06-scraping.mdxindex bf8b2d64f..7957ded1a 100644--- a/docs/introduction/06-scraping.mdx+++ b/docs/introduction/06-scraping.mdx@@ -9,14 +9,14 @@ import RunnableCodeBlock from '@site/src/components/RunnableCodeBlock';import ApiLink from '@site/src/components/ApiLink';import ExampleCode from '!!raw-loader!roa-loader!./06-example.ts';-In the [Real-world project chapter](./real-world-project#choosing-the-data-you-need), we created a list of the information we wanted to collect about the products in the example Warehouse store. Let's review that and figure out ways to access the data.+In the [Real-world project chapter](./real-world-project#choosing-the-data-you-need), you've created a list of the information you wanted to collect about the products in the example Warehouse store. Let's review that and figure out ways to access the data.-- URL-- Manufacturer-- SKU-- Title-- Current price-- Stock available+- URL+- Manufacturer+- SKU+- Title+- Current price+- Stock available@@ -24,7 +24,7 @@ In the [Real-world project chapter](./real-world-project#choosing-the-data-you-nSome information is lying right there in front of us without even having to touch the product detail pages. The `URL` we already have - the `request.url`. And by looking at it carefully, we realize that we can also extract the manufacturer from the URL (as all product urls start with `/products/<manufacturer>`). We can just split the `string` and be on our way then!-:::info+:::info `request.loaderUrl` vs `request.url`You can use `request.loadedUrl` as well. Remember the difference: `request.url` is what you enqueue, `request.loadedUrl` is what gets processed (after possible redirects).@@ -37,13 +37,13 @@ const urlPart = request.url.split('/').slice(-1); // ['sennheiser-mke-440-profesconst manufacturer = urlPart[0].split('-')[0]; // 'sennheiser'```-:::tip+:::tip Storing informationIt's a matter of preference, whether to store this information separately in the resulting dataset, or not. Whoever uses the dataset can easily parse the `manufacturer` from the `URL`, so should you duplicate the data unnecessarily? Our opinion is that unless the increased data consumption would be too large to bear, it's better to make the dataset as rich as possible. For example, someone might want to filter by `manufacturer`.:::-:::caution+:::caution Adapt and extractOne thing you may notice is that the `manufacturer` might have a `-` in its name. If that's the case, your best bet is extracting it from the details page instead, but it's not mandatory. At the end of the day, you should always adjust and pick the best solution for your use case, and website you are crawling.@@ -57,13 +57,13 @@ Now it's time to add more data to the results. Let's open one of the product detBy using the element selector tool, you can see that the title is there under an `<h1>` tag, as titles should be. The `<h1>` tag is enclosed in a `<div>` with class `product-meta`. We can leverage this to create a combined selector `.product-meta h1`. It selects any `<h1>` element that is a child of a different element with the class `product-meta`.-:::tip+:::tip Verifying selectors with DevToolsRemember that you can press CTRL+F (or CMD+F on Mac) in the **Elements** tab of DevTools to open the search bar where you can quickly search for elements using their selectors. Always verify your scraping process and assumptions using the DevTools. It's faster than changing the crawler code all the time.:::-To get the title, we need to find it using `Playwright` and a `.product-meta h1` locator, which selects the `<h1>` element we're looking for, or throws, if it finds more than one. That's good. It's usually better to crash the crawler than silently return bad data.+To get the title, you need to find it using `Playwright` and a `.product-meta h1` locator, which selects the `<h1>` element you're looking for, or throws, if it finds more than one. That's good. It's usually better to crash the crawler than silently return bad data.```jsconst title = await page.locator('.product-meta h1').textContent();@@ -71,7 +71,7 @@ const title = await page.locator('.product-meta h1').textContent();### SKU-Using the DevTools, we find that the product SKU is inside a `<span>` tag with a class `product-meta__sku-number`. And since there's no other `<span>` with that class on the page, we can safely use it.+Using the DevTools, you can find that the product SKU is inside a `<span>` tag with a class `product-meta__sku-number`. And since there's no other `<span>` with that class on the page, you can safely use it.@@ -81,7 +81,7 @@ const sku = await page.locator('span.product-meta__sku-number').textContent();### Current price-DevTools tell us that the `currentPrice` can be found in a `<span>` element tagged with the `price` class. But it also shows us that it is nested as raw text alongside another `<span>` element with the `visually-hidden` class. We don't want that, so we need to filter it out, and we can use the `hasText` helper for that.+DevTools can tell you that the `currentPrice` can be found in a `<span>` element tagged with the `price` class. But it also shows that it is nested as raw text alongside another `<span>` element with the `visually-hidden` class. You don't want that, so you need to filter it out, and the `hasText` helper can be used for that for that.@@ -98,13 +98,13 @@ const rawPrice = currentPriceString.split('$')[1];const price = Number(rawPrice.replaceAll(',', ''));```-It might look a little too complex at first glance, but let's walk through what we did. First off, we find the right part of the `price` span (specifically the actual price) by filtering the element that has the `$` sign in it. When we do that, we will get a string similar to `Sale price$1,398.00`. This, by itself, is not that useful, so we extract the actual numeric part by splitting by the `$` sign.+It might look a little too complex at first glance, but let's walk through what you did. First off, you find the right part of the `price` span (specifically the actual price) by filtering the element that has the `$` sign in it. When you do that, you will get a string similar to `Sale price$1,398.00`. This, by itself, is not that useful, so you extract the actual numeric part by splitting by the `$` sign.-Once we do that, we receive a string that represents our price, but we will be converting it to a number. We do that by replacing all the commas with nothingness (so we can parse it into a number), then we parse it into a number using `Number()`.+Once you do that, you receive a string that represents our price, but you will be converting it to a number. You do that by replacing all the commas with nothingness (so we can parse it into a number), then it is parsed into a number using `Number()`.### Stock available-We're finishing up with the `availableInStock`. We can see there is a span with the `product-form__inventory` class, and it contains the text `In stock`. We can use the `hasText` helper again to filter out the right element.+You're finishing up with the `availableInStock`. There is a span with the `product-form__inventory` class, and it contains the text `In stock`. You can use the `hasText` helper again to filter out the right element.```jsconst inStockElement = await page@@ -117,9 +117,9 @@ const inStockElement = await pageconst inStock = (await inStockElement.count()) > 0;```-For this, all we care about is whether the element exists or not, so we can use the `count()` method to check if there are any elements that match our selector. If there are, we know that the product is in stock.+For this, all that matter is whether the element exists or not, so you can use the `count()` method to check if there are any elements that match our selector. If there are, that means the product is in stock.-And there we have it! All the data we needed. For the sake of completeness, let's add all the properties together, and we're good to go.+And there you have it! All the needed data. For the sake of completeness, let's add all the properties together, and you're good to go.```jsconst urlPart = request.url.split('/').slice(-1); // ['sennheiser-mke-440-professional-stereo-shotgun-microphone-mke-440']@@ -151,7 +151,7 @@ const inStock = (await inStockElement.count()) > 0;## Trying it out-We have everything we need so grab our newly created scraping logic, dump it into our original `requestHandler()` and see the magic happen!+You have everything that is needed, so grab your newly created scraping logic, dump it into your original `requestHandler()` and see the magic happen!<RunnableCodeBlock className="language-js" type="playwright">{ExampleCode}@@ -170,6 +170,6 @@ When you run the crawler, you will see the crawled URLs and their scraped data p}```-## Next lesson+## Next steps-In the next lesson, we will show you how to save the data you scraped to the disk for further processing.+Next, you'll see how to save the data you scraped to the disk for further processing.diff --git a/docs/introduction/07-saving-data.mdx b/docs/introduction/07-saving-data.mdxindex 8f059d74c..dfcd37ce2 100644--- a/docs/introduction/07-saving-data.mdx+++ b/docs/introduction/07-saving-data.mdx@@ -8,7 +8,7 @@ import RunnableCodeBlock from '@site/src/components/RunnableCodeBlock';import ApiLink from '@site/src/components/ApiLink';import Example from '!!raw-loader!roa-loader!./07-example.ts';-A data extraction job would not be complete without saving the data for later use and processing. We've come to the final and most difficult part of this tutorial so make sure to pay attention very carefully!+A data extraction job would not be complete without saving the data for later use and processing. You've come to the final and most difficult part of this tutorial so make sure to pay attention very carefully!First, add a new import to the top of the file:@@ -22,7 +22,7 @@ Then, replace the `console.log(results)` call with:await Dataset.pushData(results);```-and that's it. Unlike earlier, we are being serious now. That's it, we're done. The final code looks like this:+and that's it. Unlike earlier, we are being serious now. That's it, you're done. The final code looks like this:<RunnableCodeBlock className="language-js" type="playwright">{Example}@@ -32,7 +32,7 @@ and that's it. Unlike earlier, we are being serious now. That's it, we're done.​<ApiLink to="core/class/Dataset#pushData">`Dataset.pushData()`</ApiLink> is a function that saves data to the default <ApiLink to="core/class/Dataset">`Dataset`</ApiLink>. `Dataset` is a storage designed to hold data in a format similar to a table. Each time you call `Dataset.pushData()` a new row in the table is created, with the property names serving as column titles. In the default configuration, the rows are represented as JSON files saved on your disk, but other storage systems can be plugged into Crawlee as well.-:::info+:::info Automatic dataset initialization in CrawleeEach time you start Crawlee a default `Dataset` is automatically created, so there's no need to initialize it or create an instance first. You can create as many datasets as you want and even give them names. For more details see the [Result storage guide](../guides/result-storage#dataset) and the <ApiLink to="core/class/Dataset#open">`Dataset.open()`</ApiLink> function.@@ -42,18 +42,18 @@ Each time you start Crawlee a default `Dataset` is automatically created, so theUnless you changed the configuration that Crawlee uses locally, which would suggest that you knew what you were doing, and you didn't need this tutorial anyway, you'll find your data in the `storage` directory that Crawlee creates in the working directory of the running script:-```+```bash{PROJECT_FOLDER}/storage/datasets/default/```The above folder will hold all your saved data in numbered files, as they were pushed into the dataset. Each file represents one invocation of `Dataset.pushData()` or one table row.-:::tip+:::tip Single file data storage optionsIf you would like to store your data in a single big file, instead of many small ones, see the [Result storage guide](../guides/result-storage#key-value-store) for Key-value stores.:::-## Next lesson+## Next steps-In the next lesson, we will show you some improvements that you can add to your crawler code that will make it more readable and maintainable in the long run.+Next, you'll see some improvements that you can add to your crawler code that will make it more readable and maintainable in the long run.diff --git a/docs/introduction/08-refactoring.mdx b/docs/introduction/08-refactoring.mdxindex 8c526cdcb..450048013 100644--- a/docs/introduction/08-refactoring.mdx+++ b/docs/introduction/08-refactoring.mdx@@ -9,11 +9,11 @@ import Admonition from '@theme/Admonition';It may seem that the data is extracted and the crawler is done, but honestly, this is just the beginning. For the sake of brevity, we've completely omitted error handling, proxies, logging, architecture, tests, documentation and other stuff that a reliable software should have. The good thing is, **error handling is mostly done by Crawlee itself**, so no worries on that front, unless you need some custom magic.-:::info+:::info Navigating automatic bot-protextion avoidance-If you've got to this point and are wondering where all the **anti-blocking, bot-protection avoiding stealthy features** are, you're right, we haven't shown you any. But that's the point! They are **automatically used** with the default configuration.+You might be wondering about the **anti-blocking, bot-protection avoiding stealthy features** and why we haven't highlighted them yet. The reason is straightforward: these features are **automatically used** within the default configuration, providing a smooth start without manual adjustments. However, the default configuration, while powerful, may not cover every scenario.-That does not mean the default configuration can handle everything, but it should get you far enough. If you want to learn more, browse the [Avoid getting blocked](../guides/avoid-blocking), [Proxy management](../guides/proxy-management) and [Session management](../guides/session-management) guides.+If you want to learn more, browse the [Avoid getting blocked](../guides/avoid-blocking), [Proxy management](../guides/proxy-management) and [Session management](../guides/session-management) guides.:::@@ -23,9 +23,9 @@ Anyway, to promote good coding practices, let's look at how you can use a <ApiLiIn the following code we've made several changes:-- Split the code into multiple files.-- Replaced `console.log` with the Crawlee logger for nicer, colourful logs.-- Added a `Router` to make our routing cleaner, without `if` clauses.+- Split the code into multiple files.+- Replaced `console.log` with the Crawlee logger for nicer, colourful logs.+- Added a `Router` to make our routing cleaner, without `if` clauses.In our `main.mjs` file, we place the general structure of the crawler:@@ -136,7 +136,7 @@ router.addDefaultHandler(async ({ request, page, enqueueLinks, log }) => {});```-Let's describe the changes a bit more in detail. We hope that in the end, you will agree that this structure makes the crawler more readable and manageable.+Let's explore the changes in more detail. We believe these modification will enhance the readability and manageability of the crawler.## Splitting your code into multiple files@@ -144,16 +144,16 @@ There's no reason not to split your code into multiple files and keep your logic## Using Crawlee `log` instead of `console.log`-We won't go to great lengths here to talk about `log` object from Crawlee, because you can read it all in the <ApiLink to="core/class/Log">documentation</ApiLink>, but there's just one thing that we need to stress: **log levels**.+We won't go to great lengths here to talk about `log` object from Crawlee, because you can read all about it in the <ApiLink to="core/class/Log">documentation</ApiLink>, but there's just one thing that we need to stress: **log levels**.Crawlee `log` has multiple log levels, such as `log.debug`, `log.info` or `log.warning`. It not only makes your log more readable, but it also allows selective turning off of some levels by either calling the `log.setLevel()` function or by setting the `CRAWLEE_LOG_LEVEL` environment variable. Thanks to this you can add a lot of debug logs to your crawler without polluting your log when they're not needed, but ready to help when you encounter issues.## Using a router to structure your crawling-At first, it might seem more readable using just a simple `if / else` statement to select different logic based on the crawled pages, but trust us, it becomes far less impressive when working with more than two different pages, and it definitely starts to fall apart when the logic to handle each page spans tens or hundreds of lines of code.+Initially, using a simple `if/else` statement for selecting different logic based on the crawled pages might appear more readable. However, this approach can become cumbersome with more than two types of pages, especially when the logic for each page extends over dozens or even hundreds of lines of code.It's good practice in any programming language to split your logic into bite-sized chunks that are easy to read and reason about. Scrolling through a thousand line long `requestHandler()` where everything interacts with everything and variables can be used everywhere is not a beautiful thing to do and a pain to debug. That's why we prefer the separation of routes into their own files.-## Next lesson+## Next steps-In the next and final lesson, we will show you how you can deploy your Crawlee project to the cloud. If you used the CLI to bootstrap your project, you already have a **Dockerfile** ready, and the next section will show you how to deploy it to the [Apify Platform](../deployment/apify-platform) with ease.+In the next and final step, you'll see how to deploy your Crawlee project to the cloud. If you used the CLI to bootstrap your project, you already have a **Dockerfile** ready, and the next section will show you how to deploy it to the [Apify Platform](../deployment/apify-platform) with ease.diff --git a/docs/introduction/09-deployment.mdx b/docs/introduction/09-deployment.mdxindex 5273181be..65f76c6ed 100644--- a/docs/introduction/09-deployment.mdx+++ b/docs/introduction/09-deployment.mdx@@ -7,13 +7,13 @@ description: Deploying Crawlee projects to the Apify Platform## Apify Platform-Crawlee is developed by [**Apify**](https://apify.com), the web scraping and automation platform. You could say it is the **home of Crawlee projects**. In this section we will show you how to deploy the crawler there with just a few simple steps. You can deploy a **Crawlee** project wherever you want, but using the [**Apify Platform**](https://console.apify.com) will give you the best experience.+Crawlee is developed by [**Apify**](https://apify.com), the web scraping and automation platform. You could say it is the **home of Crawlee projects**. In this section you'll see how to deploy the crawler there with just a few simple steps. You can deploy a **Crawlee** project wherever you want, but using the [**Apify Platform**](https://console.apify.com) will give you the best experience.-In case you want to deploy your Crawlee project to other platforms, check out the [**Deployment**](../deployment) section of the documentation instead.+In case you want to deploy your Crawlee project to other platforms, check out the [**Deployment**](../deployment) section.With a few simple steps, you can convert your Crawlee project into a so-called **Actor**. Actors are serverless micro-apps that are easy to develop, run, share, and integrate. The infra, proxies, and storages are ready to go. [Learn more about Actors](https://apify.com/actors).-:::info+:::info Choosing between Crawlee CLI and Apify CLI for project setupWe started this guide by using the Crawlee CLI to bootstrap the project - it offers the basic Crawlee templates, including a ready-made `Dockerfile`. If you know you will be deploying your project to the Apify Platform, you might want to start with the Apify CLI instead. It also offers several project templates, and those are all set up to be used on the Apify Platform right ahead.@@ -23,13 +23,14 @@ We started this guide by using the Crawlee CLI to bootstrap the project - it offThe first step will be installing two new dependencies:-- Apify SDK, a toolkit for working with the Apify Platform. This will allow us to wire the storages (e.g. `RequestQueue` and `Dataset`) to the Apify cloud products. This will be a dependency of our Node.js project.+- Apify SDK, a toolkit for working with the Apify Platform. This will allow us to wire the storages (e.g. `RequestQueue` and `Dataset`) to the Apify cloud products. This will be a dependency of our Node.js project.```bashnpm install apify```-- Apify CLI, a command-line tool that will help us with authentication and deployment. This will be a globally installed tool, you will install it only once and use it in all your Crawlee/Apify projects.+- Apify CLI, a command-line tool that will help us with authentication and deployment. This will be a globally installed tool, you will install it only once and use it in all your Crawlee/Apify projects.+```bashnpm install -g apify-cli```@@ -76,7 +77,7 @@ await Actor.exit();The `Actor.init()` call will configure Crawlee to use the Apify API instead of its default memory storage interface. It also sets up few other things, like listening to the platform events via websockets. The `Actor.exit()` call then handles graceful shutdown - it will close the open handles created by the `Actor.init()` call, as without that, the Node.js process would be stuck.-:::info+:::info Understanding `Actor.ini()` behavior with environment variablesThe `Actor.init()` call works conditionally based on the environment variables, namely based on the `APIFY_IS_AT_HOME` env var, which is set to `true` on the Apify Platform. This means that your project will remain working the same locally, but will use the Apify API when deployed to the Apify Platform.@@ -84,7 +85,7 @@ The `Actor.init()` call works conditionally based on the environment variables,## Initializing the project-We will also need to initialize the project for Apify, to do that, let's use the Apify CLI again:+You will also need to initialize the project for Apify, to do that, use the Apify CLI again:```bashapify init@@ -94,7 +95,7 @@ This will create a folder called `.actor`, and an `actor.json` file inside it -## Ship it!-And that's all, our project is now ready to be published on the Apify Platform. We will use the Apify CLI once more to do that:+And that's all, your project is now ready to be published on the Apify Platform. You can use the Apify CLI once more to do that:```bashapify push@@ -104,7 +105,7 @@ This command will create an archive from your project, upload it to the Apify Pl## Learning more about web scraping-:::tip+:::tip Explore Apify Academy ResourcesIf you want to learn more about web scraping and browser automation, check out the [Apify Academy](https://developers.apify.com/academy). It's full of courses and tutorials on the topic. From beginner to advanced. And the best thing: **It's free and open source** ❤️diff --git a/docs/introduction/index.mdx b/docs/introduction/index.mdxindex b64688861..2fc99fbd2 100644--- a/docs/introduction/index.mdx+++ b/docs/introduction/index.mdx@@ -44,6 +44,6 @@ The goal of the introduction is to provide a step-by-step guide to the most impo- Use **Playwright** and **Puppeteer** with the same interface- **Chrome**, **Firefox**, **Webkit** and many others-## Next lesson+## Next steps-In the next lesson you will install Crawlee and learn how to bootstrap projects with the Crawlee CLI.+Next, you will install Crawlee and learn how to bootstrap projects with the Crawlee CLI.