You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f68d0d7
Browse filesBrowse the repository at this point in the historyBrowse files
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>
Copy file name to clipboardExpand all lines: sources/academy/platform/expert_scraping_with_apify/apify_api_and_client.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ pagination: true
11
11
12
12
---
13
13
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.
15
15
16
16
> 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.
17
17
@@ -30,14 +30,14 @@ You can use one of the two main ways to programmatically interact with the Apify
30
30
31
31
## Our task
32
32
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:
34
34
35
35
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.
37
37
38
38
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.
39
39
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:
41
41
42
42
```json
43
43
{
@@ -62,4 +62,4 @@ The new Actor should take the following input values, which be mapped to paramet
62
62
63
63
## Next up {#next}
64
64
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.
Copy file name to clipboardExpand all lines: sources/academy/platform/expert_scraping_with_apify/managing_source_code.md
+12-9Lines changed: 12 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,15 +11,15 @@ pagination: true
11
11
12
12
---
13
13
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.
15
15
16
16
## Learning 🧠 {#learning}
17
17
18
18
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.
19
19
20
20
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.
21
21
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.
23
23
24
24
## Knowledge check 📝 {#quiz}
25
25
@@ -35,15 +35,18 @@ First, we must initialize a GitHub repository (you can use Gitlab if you like, b
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.
39
39
40
-

40
+

41
41
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:
43
43
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.
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**.
47
50
48
51
Then, go ahead and paste the link to your repository into the **Git URL** text field and click **Save**.
49
52
@@ -55,11 +58,11 @@ And you're done! 🎉
55
58
56
59
## Quick chat about code management {#code-management}
57
60
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.
59
62
60
63
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.
61
64
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.
Copy file name to clipboardExpand all lines: sources/academy/platform/expert_scraping_with_apify/solutions/using_api_and_client.md
+72-60Lines changed: 72 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,32 +11,38 @@ pagination: true
11
11
12
12
---
13
13
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:
15
15
16
16
```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
22
25
```
23
26
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**:
25
28
26
29
```text
27
-
$ apify create filter-actor
30
+
$ apify create actor-caller
31
+
✔ What do you want to build? Any use case
28
32
✔ 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
JavaScript minimal site crawler (Crawlee + Cheerio)
40
+
JavaScript test runner (Cypress)
41
+
❯ Empty JavaScript Actor
36
42
...
37
43
```
38
44
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:
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.
59
65
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:
61
67
62
68
```js
63
69
constwithClient=async () => {
64
70
constclient=Actor.newClient();
65
71
consttask=client.task(TASK);
66
72
67
-
const { id } =awaittask.call({ memory });
73
+
const { id } =awaittask.call(undefined, { memory });
68
74
};
69
75
```
70
76
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`.
72
78
73
79
```js
74
80
constwithClient=async () => {
75
81
constclient=Actor.newClient();
76
82
consttask=client.task(TASK);
77
83
78
-
const { id } =awaittask.call({ memory });
84
+
const { id } =awaittask.call(undefined, { memory });
79
85
80
86
constdataset=client.run(id).dataset();
81
87
@@ -100,7 +106,7 @@ const withAPI = async () => {
100
106
};
101
107
```
102
108
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:
104
110
105
111
```js
106
112
constwithAPI=async () => {
@@ -147,46 +153,52 @@ if (useClient) await withClient();
147
153
elseawaitwithAPI();
148
154
```
149
155
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:
151
157
152
-
```json
158
+
```json title=".actor/input_schema.json"
153
159
{
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
+
}
165
191
},
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.",
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
+
190
202
## Final code {#final-code}
191
203
192
204
To ensure we're on the same page, here is what the final code looks like:
const { id } =awaittask.call(undefined, { memory });
209
221
210
222
constdataset=client.run(id).dataset();
211
223
@@ -247,9 +259,9 @@ await Actor.exit();
247
259
248
260
**Q: What is the relationship between the Apify API and Apify client? Are there any significant differences?**
249
261
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.
251
263
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.
253
265
254
266
**Q: How do you pass input when running an Actor or task via API?**
Copy file name to clipboardExpand all lines: sources/academy/platform/expert_scraping_with_apify/tasks_and_storage.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,12 @@ Storage allows us to save persistent data for further processing. As you'll lear
34
34
2. What are the differences between default (unnamed) and named storage? Which one would you use for everyday usage?
35
35
3. What is data retention, and how does it work for all types of storages (default and named)?
36
36
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.
0 commit comments