Skip to content

Commit f68d0d7

Browse files
honzajavorekclaudeszaganek
authored
docs(academy): update expert course lessons II-IV to academy-amazon-scraper (#3237)
<img width="1024" height="512" alt="dramatic-chipmunk" src="https://github.com/user-attachments/assets/8b8d73f8-84aa-4a69-b961-67c4326b3940" /> ## What is this about? I'm trying to delete the legacy JS course. To delete it, I need to update the expert scraping course so that it doesn't depend on the legacy JS course. My aim is to base it on top of [academy-amazon-scraper](https://github.com/apify-projects/academy-amazon-scraper) instead, which I updated and fixed. This PR covers lessons II–IV (source code, tasks and storage, API and client) and the API & client solution. ## What this isn't about? I'm trying to make the least number of improvements to the expert course so that it's based on academy-amazon-scraper, provides correct, up-to-date information, and so that the guidance in it actually works in November 2026. I'm not rewriting the course. I can see many sentences I would write in a different way, but I sit on my hands and try not to touch them, so this doesn't snowball too much. ## Fixes - Lesson II tells readers to repoint `origin` to their new GitHub repository, because the `git remote add origin` that GitHub suggests fails on a clone of the starter. The Console step uses the current **Source type** label, and the outdated screenshot of the old source type dropdown is gone. The image file itself stays, because the deploying lesson still uses it. #3276 is in the making to replace it there. - Lesson III asks readers to create the `academy-amazon-scraper-task` that lesson IV calls. - The solution passes `memory` as a run option instead of an input override, saves under `OUTPUT`, matches the current `apify create` walkthrough and input schema location, and warns readers to give `actor-caller` full permissions before they hit a `403`. - A few typos, wrong lesson numbers, and a broken link that were already on master are fixed. - To match #3238, the input schema block in this solution names its file with `title=`, and file names and names from the code use backticks instead of bold, as the style guide asks. #3278 does the same for lesson I. ## How I know it works I followed the lessons on the platform: both modes of `actor-caller` wrote `OUTPUT` as CSV with only the requested fields and `maxItems` rows, and the task runs got the requested memory. ## Related stuff Closes #3120 This is split out of #3137, which is too large to review. Other: #3123, #3122, #2547, #1906 ## Still to do - [x] Honza does a final read-through and self-review before handing this over to other humans :))) --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com>
1 parent c389a1b commit f68d0d7

4 files changed

Lines changed: 95 additions & 74 deletions

File tree

‎sources/academy/platform/expert_scraping_with_apify/apify_api_and_client.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pagination: true
1111

1212
---
1313

14-
You can use one of the two main ways to programmatically interact with the Apify platform: by directly using [Apify's RESTful API](/api/v2), or by using the [JavaScript](/api/client/js) and [Python](/api/client/python) API clients. In the next two lessons, we'll be focusing on the first two.
14+
You can use one of the two main ways to programmatically interact with the Apify platform: by directly using [Apify's RESTful API](/api/v2), or by using the [JavaScript](/api/client/js) and [Python](/api/client/python) API clients. In this lesson, we'll be focusing on the API and the JavaScript client.
1515

1616
> Apify's API and JavaScript API client allow us to do anything a regular user can do when interacting with the platform's web interface, only programmatically.
1717
@@ -30,14 +30,14 @@ You can use one of the two main ways to programmatically interact with the Apify
3030

3131
## Our task
3232

33-
We'll be creating another new Actor, which will have two jobs:
33+
In the previous lesson, we created the **academy-amazon-scraper-task** task for our Amazon Actor. Now, we'll be creating another new Actor, which will have two jobs:
3434

3535
1. Programmatically call the task for the Amazon Actor.
36-
2. Export its results into CSV format under a new key called **OUTPUT.csv** in the default key-value store.
36+
2. Export its results into CSV format under a new key called `OUTPUT` in the default key-value store.
3737

3838
Though it's a bit unintuitive, this is a perfect activity for learning how to use both the Apify API and the Apify JavaScript client.
3939

40-
The new Actor should take the following input values, which be mapped to parameters in the API calls:
40+
The new Actor should take the following input values, which will be mapped to parameters in the API calls:
4141

4242
```json
4343
{
@@ -62,4 +62,4 @@ The new Actor should take the following input values, which be mapped to paramet
6262

6363
## Next up {#next}
6464

65-
[Lesson VI](./migrations_maintaining_state.md) will teach us everything we need to know about migrations and how to handle them properly to avoid losing any state; therefore, increasing the reliability of our `demo-actor` Amazon scraper.
65+
[Lesson V](./migrations_maintaining_state.md) will teach us everything we need to know about migrations and how to handle them properly to avoid losing any state, which makes our **academy-amazon-scraper** more reliable.

‎sources/academy/platform/expert_scraping_with_apify/managing_source_code.md‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ pagination: true
1111

1212
---
1313

14-
In this brief lesson, we'll discuss how to better manage an Actor's source code. Up 'til now, you've been developing your scripts locally, and then pushing the code directly to the Actor on the Apify platform; however, there is a much more optimal (and standard) way.
14+
In this brief lesson, we'll discuss how to better manage an Actor's source code. Until now, you've worked on your Actors' code locally and pushed it directly to the Apify platform. However, there's a better and more standard way.
1515

1616
## Learning 🧠 {#learning}
1717

1818
Thus far, every time we've updated our code on the Apify platform, we've used the `apify push` CLI command; however, this can be problematic for a few reasons - mainly because, if someone else wants to make a change to/maintain your code, they don't have access to it, as it is on your local machine.
1919

2020
If you're not yet familiar with Git, please get familiar with it through the [Git documentation](https://git-scm.com/docs), then take a quick moment to read about [GitHub integration](/integrations/github) in the Apify docs.
2121

22-
Also, try to explore the **Multifile editor** in one of the Actors you developed in the previous lessons before moving forward.
22+
Also, try to explore the **Multifile editor** in **filter-actor**, which you created in the previous lesson, before moving forward.
2323

2424
## Knowledge check 📝 {#quiz}
2525

@@ -35,15 +35,18 @@ First, we must initialize a GitHub repository (you can use Gitlab if you like, b
3535

3636
## Integrating GitHub source code {#integrating-github}
3737

38-
First, let's create a repository. This can be done [in a number of ways](https://kbroman.org/github_tutorial/pages/init.html), but in this lesson, we'll do it by creating the remote repository on GitHub's website:
38+
First, let's create a repository. This can be done [in a number of ways](https://kbroman.org/github_tutorial/pages/init.html), but in this lesson, we'll do it by creating the remote repository on GitHub's website. Open GitHub's **+** menu and select **New repository**. Name it **academy-amazon-scraper** and create it empty, without a README, `.gitignore`, or license, because we'll push our existing code into it.
3939

40-
![Create a new GitHub repo](./images/github-new-repo.png)
40+
![GitHub's + menu open, with New repository highlighted](./images/github-new-repo.png)
4141

42-
Then, we'll run the commands it tells us in our terminal (while within the **demo-actor** directory) to initialize the repository locally, and then push all of the files to the remote one.
42+
GitHub then suggests commands for pushing an existing repository, but we can't use them as they are. We cloned **academy-amazon-scraper** from the starter repository, so its `origin` remote already points to `apify-projects/academy-amazon-scraper`, and `git remote add origin …` would fail with `remote origin already exists`. Instead, we'll point `origin` to our new repository and push all of the files to it. Run the following in the **academy-amazon-scraper** directory, with your own repository URL:
4343

44-
After you've created your repo, in the Apify platform navigate to your Amazon scraping Actor that we called **demo-actor**. In the **Source** tab, click the dropdown menu under **Source code** and select **Git repository**. By default, this is set to **Web IDE**, which is what we've been using so far.
44+
```bash
45+
git remote set-url origin https://github.com/YOUR_USERNAME/academy-amazon-scraper.git
46+
git push -u origin main
47+
```
4548

46-
![Select source code location](./images/select-source-location.png)
49+
Once the code is on GitHub, open your **academy-amazon-scraper** Actor in Apify Console. On the **Source** tab, change **Source type** from **Web IDE**, which is what we've been using so far, to **Git repository**.
4750

4851
Then, go ahead and paste the link to your repository into the **Git URL** text field and click **Save**.
4952

@@ -55,11 +58,11 @@ And you're done! 🎉
5558

5659
## Quick chat about code management {#code-management}
5760

58-
This was a bit of overhead, but the good news is that you don't ever have to configure this stuff again for this Actor. Now, every time the content of your **main**/**master** branch changes, the Actor on the Apify platform will rebuild based on the newest code.
61+
This was a bit of overhead, but the good news is that you don't ever have to configure this stuff again for this Actor. Now, every time the content of your `main`/`master` branch changes, the Actor on the Apify platform will rebuild based on the newest code.
5962

6063
Think of it as combining two steps into one. Normally, you'd have to do a `git push` from your terminal to get the newest code onto GitHub, then run `apify push` to push it to the platform.
6164

62-
It's also important to know that GitHub/Gitlab repository integration is standard practice. As projects grow and the number of contributors and maintainers increases, it only makes sense to have a GitHub repository integrated with the project's Actor. For the remainder of this course, all Actors created will be integrated with a GitHub repository.
65+
It's also important to know that GitHub/GitLab repository integration is standard practice. As projects grow and the number of contributors and maintainers increases, it only makes sense to have a GitHub repository integrated with the project's Actor. For small helper Actors, `apify push` is still handy, so later in this course we'll use it to deploy the new Actors we create. Feel free to integrate them with a GitHub repository instead.
6366

6467
## Next up {#next}
6568

‎sources/academy/platform/expert_scraping_with_apify/solutions/using_api_and_client.md‎

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,38 @@ pagination: true
1111

1212
---
1313

14-
Since we need to create another Actor, we'll once again use the `apify create` command and start from an empty template. This time, let's call our project **actor-caller**:
14+
Since we need to create another Actor, we'll once again use the `apify create` command and start from an empty template. This time, let's call our project **actor-caller**. When asked what you want to build, select **Any use case** again:
1515

1616
```text
17-
$ apify create filter-caller
18-
? Choose the programming language of your new Actor:
19-
❯ JavaScript
20-
TypeScript
21-
Python
17+
$ apify create actor-caller
18+
? What do you want to build?
19+
Web scraper
20+
AI agent
21+
API & data pipeline
22+
Browser automation
23+
──────────────
24+
❯ Any use case
2225
```
2326

24-
Again, use the arrow down key to select **Empty JavaScript Project**:
27+
Again, select **JavaScript** as the programming language and use the arrow down key to select **Empty JavaScript Actor**:
2528

2629
```text
27-
$ apify create filter-actor
30+
$ apify create actor-caller
31+
✔ What do you want to build? Any use case
2832
✔ Choose the programming language of your new Actor: JavaScript
29-
? Choose a template for your new Actor. Detailed information about the template will be shown in the next step.
30-
Crawlee + Playwright + Chrome
31-
Crawlee + Playwright + Camoufox
32-
Bootstrap CheerioCrawler
33-
Cypress
34-
❯ Empty JavaScript Project
35-
Standby JavaScript Project
33+
? Choose a template for your new Actor. More info at https://apify.com/templates
34+
JavaScript site crawler (Crawlee + Cheerio)
35+
JavaScript one-page scraper (Cheerio)
36+
JavaScript browser crawler (Crawlee + Puppeteer + Chrome)
37+
JavaScript browser crawler (Crawlee + Playwright + Chrome)
38+
JavaScript stealth crawler (Crawlee + Playwright + Camoufox)
39+
JavaScript minimal site crawler (Crawlee + Cheerio)
40+
JavaScript test runner (Cypress)
41+
❯ Empty JavaScript Actor
3642
...
3743
```
3844

39-
Confirm the choices by **Install template** and wait until our new Actor is ready. Now let's also set up some boilerplate, grabbing our inputs and creating a constant variable for the task:
45+
When asked how to set up the source code, select **Local only**, and wait until our new Actor is ready. Now let's also set up some boilerplate, grabbing our inputs and creating a constant variable for the task:
4046

4147
```js
4248
import { Actor } from 'apify';
@@ -46,7 +52,7 @@ await Actor.init();
4652

4753
const { useClient, memory, fields, maxItems } = await Actor.getInput();
4854

49-
const TASK = 'YOUR_USERNAME~demo-actor-task';
55+
const TASK = 'YOUR_USERNAME~academy-amazon-scraper-task';
5056

5157
// our future code will go here
5258

@@ -57,25 +63,25 @@ await Actor.exit();
5763

5864
When using the `apify-client` package, you can create a new client instance by using `new ApifyClient()`. Within the Apify SDK however, it is not necessary to even install the `apify-client` package, as the `Actor.newClient()` function is available for use.
5965

60-
We'll start by creating a function called `withClient()` and creating a new client, then calling the task:
66+
We'll start by creating a function called `withClient()` and creating a new client, then calling the task. The first argument of `call()` overrides the task's input, so we pass `undefined` to keep the input saved in the task, and set the memory in the second argument, which holds the run options:
6167

6268
```js
6369
const withClient = async () => {
6470
const client = Actor.newClient();
6571
const task = client.task(TASK);
6672

67-
const { id } = await task.call({ memory });
73+
const { id } = await task.call(undefined, { memory });
6874
};
6975
```
7076

71-
After the task has run, we'll grab hold of its dataset, then attempt to download the items, plugging in our `maxItems` and `fields` inputs. Then, once the data has been downloaded, we'll push it to the default key-value store under a key named **OUTPUT.csv**.
77+
After the task has run, we'll get its dataset, then attempt to download the items, plugging in our `maxItems` and `fields` inputs. Then, once the data has been downloaded, we'll push it to the default key-value store under a key named `OUTPUT`.
7278

7379
```js
7480
const withClient = async () => {
7581
const client = Actor.newClient();
7682
const task = client.task(TASK);
7783

78-
const { id } = await task.call({ memory });
84+
const { id } = await task.call(undefined, { memory });
7985

8086
const dataset = client.run(id).dataset();
8187

@@ -100,7 +106,7 @@ const withAPI = async () => {
100106
};
101107
```
102108

103-
To add the query parameters to the URL, we could create a super long string literal, plugging in all of our input values; however, there is a much better way: [`URLSearchParams`](https://nodejs.org/api/url.html#new-urlsearchparams). By using `URLSearchParams`, we can add the query parameters in an object:
109+
To add the query parameters to the URL, we could create a long string literal, plugging in all of our input values. However, there is a much better way: [`URLSearchParams`](https://nodejs.org/api/url.html#new-urlsearchparams). By using `URLSearchParams`, we can add the query parameters in an object:
104110

105111
```js
106112
const withAPI = async () => {
@@ -147,46 +153,52 @@ if (useClient) await withClient();
147153
else await withAPI();
148154
```
149155

150-
And before we push to the platform, let's not forget to write an input schema in the **INPUT_SCHEMA.JSON** file:
156+
And before we push to the platform, let's not forget to write an input schema in the `.actor/input_schema.json` file:
151157

152-
```json
158+
```json title=".actor/input_schema.json"
153159
{
154-
"title": "Actor Caller",
155-
"type": "object",
156-
"schemaVersion": 1,
157-
"properties": {
158-
"memory": {
159-
"title": "Memory",
160-
"type": "integer",
161-
"description": "Select memory in megabytes.",
162-
"default": 4096,
163-
"maximum": 32768,
164-
"unit": "MB"
160+
"title": "Actor Caller",
161+
"type": "object",
162+
"schemaVersion": 1,
163+
"properties": {
164+
"memory": {
165+
"title": "Memory",
166+
"type": "integer",
167+
"description": "Select memory in megabytes.",
168+
"default": 4096,
169+
"maximum": 32768,
170+
"unit": "MB"
171+
},
172+
"useClient": {
173+
"title": "Use client?",
174+
"type": "boolean",
175+
"description": "Specifies whether the Apify JS client, or the pure Apify API should be used.",
176+
"default": true
177+
},
178+
"fields": {
179+
"title": "Fields",
180+
"type": "array",
181+
"description": "Enter the dataset fields to export to CSV",
182+
"prefill": ["title", "itemUrl", "offer"],
183+
"editor": "stringList"
184+
},
185+
"maxItems": {
186+
"title": "Max items",
187+
"type": "integer",
188+
"description": "Fill the maximum number of items to export.",
189+
"default": 10
190+
}
165191
},
166-
"useClient": {
167-
"title": "Use client?",
168-
"type": "boolean",
169-
"description": "Specifies whether the Apify JS client, or the pure Apify API should be used.",
170-
"default": true
171-
},
172-
"fields": {
173-
"title": "Fields",
174-
"type": "array",
175-
"description": "Enter the dataset fields to export to CSV",
176-
"prefill": ["title", "url", "price"],
177-
"editor": "stringList"
178-
},
179-
"maxItems": {
180-
"title": "Max items",
181-
"type": "integer",
182-
"description": "Fill the maximum number of items to export.",
183-
"default": 10
184-
}
185-
},
186-
"required": ["useClient", "memory", "fields", "maxItems"]
192+
"required": ["useClient", "memory", "fields", "maxItems"]
187193
}
188194
```
189195

196+
:::caution Grant full permissions
197+
198+
New Actors run with [limited permissions](/actors/development/permissions) by default, which don't allow them to start a task you own. After you push **actor-caller** to the platform, open its **Settings** tab and in the **Actor permissions** section, select **Full permissions**. Otherwise, the run fails with a `403 insufficient-permissions` error when it tries to start the task.
199+
200+
:::
201+
190202
## Final code {#final-code}
191203

192204
To ensure we're on the same page, here is what the final code looks like:
@@ -199,13 +211,13 @@ await Actor.init();
199211

200212
const { useClient, memory, fields, maxItems } = await Actor.getInput();
201213

202-
const TASK = 'YOUR_USERNAME~demo-actor-task';
214+
const TASK = 'YOUR_USERNAME~academy-amazon-scraper-task';
203215

204216
const withClient = async () => {
205217
const client = Actor.newClient();
206218
const task = client.task(TASK);
207219

208-
const { id } = await task.call({ memory });
220+
const { id } = await task.call(undefined, { memory });
209221

210222
const dataset = client.run(id).dataset();
211223

@@ -247,9 +259,9 @@ await Actor.exit();
247259

248260
**Q: What is the relationship between the Apify API and Apify client? Are there any significant differences?**
249261

250-
**A:** The Apify client mimics the Apify API, so there aren't any super significant differences. It's super handy as it helps with managing the API calls (parsing, error handling, retries, etc) and even adds convenience functions.
262+
**A:** The Apify client mimics the Apify API, so there aren't any significant differences. It's handy because it helps with managing the API calls (such as parsing, error handling, retries) and even adds convenience functions.
251263

252-
The one main difference is that the Apify client automatically uses [**exponential backoff**](/api/client/js/docs#retries-with-exponential-backoff) to deal with errors.
264+
The one main difference is that the Apify client automatically uses [**exponential backoff**](/api/client/js/docs/concepts/error-handling#retries-with-exponential-backoff) to deal with errors.
253265

254266
**Q: How do you pass input when running an Actor or task via API?**
255267

‎sources/academy/platform/expert_scraping_with_apify/tasks_and_storage.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ Storage allows us to save persistent data for further processing. As you'll lear
3434
2. What are the differences between default (unnamed) and named storage? Which one would you use for everyday usage?
3535
3. What is data retention, and how does it work for all types of storages (default and named)?
3636

37+
## Our task
38+
39+
In the next lesson, we'll run our Amazon scraper programmatically through a task, so let's create one now. In Apify Console, open the **academy-amazon-scraper** Actor and select **Save as a new task**. Set the keyword to `headphones` and save the task.
40+
41+
Then select the task's caption on its detail page and rename it to **academy-amazon-scraper-task**. The next lesson refers to the task by this name, so make sure it matches. Finally, run the task to check that it works.
42+
3743
[**Solution**](./solutions/using_storage_creating_tasks.md)
3844

3945
## Next up {#next}

0 commit comments

Comments
 (0)