Skip to content

refactor: change Academy code examples to use Crawlee router#2293

Merged
honzajavorek merged 2 commits intomasterfrom
honzajavorek/router
Mar 24, 2026
Merged

refactor: change Academy code examples to use Crawlee router#2293
honzajavorek merged 2 commits intomasterfrom
honzajavorek/router

Conversation

@honzajavorek
Copy link
Collaborator

@honzajavorek honzajavorek commented Feb 27, 2026

Fix #2181, address #2097 (comment) by @B4nan


Note

Low Risk
Low risk documentation/exercise refactor that changes sample code structure to the newer Crawlee router API without altering the scraping behavior.

Overview
Refactors the Crawlee lesson (12_framework.md) to construct CheerioCrawler without an inline requestHandler and instead register routing via crawler.router.addDefaultHandler() plus labeled addHandler() functions (e.g. DETAIL, IMDB_SEARCH, IMDB).

Updates the associated exercise solutions (crawlee_f1_drivers.mjs, crawlee_netflix_ratings.mjs) to match the router-based pattern, removing request.label branching and splitting listing/search/detail logic into dedicated handlers while keeping the same data extraction and dataset export steps.

Written by Cursor Bugbot for commit 1aa2eb6. Configure here.

@honzajavorek honzajavorek added the t-academy Issues related to Web Scraping and Apify academies. label Feb 27, 2026
@honzajavorek honzajavorek requested a review from TC-MO as a code owner February 27, 2026 10:20
@honzajavorek honzajavorek changed the title refactor: use router refactor: use Crawlee router Feb 27, 2026
@honzajavorek honzajavorek changed the title refactor: use Crawlee router refactor: change Academy code examples to use Crawlee router Feb 27, 2026
@apify-service-account
Copy link

Preview for this PR was built for commit 1aa2eb66 and is ready at https://pr-2293.preview.docs.apify.com!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the JavaScript Academy “Using a framework” lesson and its two associated Crawlee exercise solutions to use a router-based request handling structure instead of request.label branching inside a single inline requestHandler.

Changes:

  • Update lesson code examples to register handlers via addDefaultHandler() and labeled addHandler() routes.
  • Refactor crawlee_f1_drivers.mjs and crawlee_netflix_ratings.mjs exercise solutions to split logic into dedicated router handlers.
  • Minor variable naming adjustment in the Netflix/IMDb exercise handler logic.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
sources/academy/webscraping/scraping_basics_javascript/exercises/crawlee_netflix_ratings.mjs Refactors the Netflix → IMDb workflow to router handlers (default, IMDB_SEARCH, IMDB).
sources/academy/webscraping/scraping_basics_javascript/exercises/crawlee_f1_drivers.mjs Refactors listing vs. detail handling into router default + DRIVER handler.
sources/academy/webscraping/scraping_basics_javascript/12_framework.md Updates lesson narrative and snippets to demonstrate the router-based approach.

@apify-service-account
Copy link

Preview for this PR was built for commit 5ff2b518 and is ready at https://pr-2293.preview.docs.apify.com!

Copy link
Member

@B4nan B4nan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you change the indents on purpose? (4 -> 2 spaces)

@danpoletaev danpoletaev force-pushed the honzajavorek/router branch from 5ff2b51 to 41d7ed0 Compare March 6, 2026 21:56
@apify-service-account
Copy link

Preview for this PR was built for commit 41d7ed02 and is ready at https://pr-2293.preview.docs.apify.com!

@B4nan B4nan force-pushed the honzajavorek/router branch from 41d7ed0 to 1aa2eb6 Compare March 6, 2026 22:56
@apify-service-account
Copy link

Preview for this PR was built for commit 1aa2eb66 and is ready at https://pr-2293.preview.docs.apify.com!

@honzajavorek
Copy link
Collaborator Author

@B4nan Thanks for the review! Without the missing awaits the examples couldn't work 🤦‍♂️ I hope it's all fixed now.

@apify-service-account
Copy link

Preview for this PR was built for commit 3a947dd2 and is ready at https://pr-2293.preview.docs.apify.com!

Copy link
Member

@B4nan B4nan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw not sure if you're into agentic development, but it would be great to let an agent read through all the tutorials and actually try them locally, this approach worked great for me. If you don't have any claude/codex/whatever subscription, someone from Apify could run this.

@honzajavorek
Copy link
Collaborator Author

I have a subscription, but not a big one. I guess this would drain my tokens really fast. @TC-MO do you think you could do this? We could have it as a side quest to improve the docs, similar to the PRs from @mtrunkat, but I'd be cautious about reviewing the work it will generate, so we better split this into self-contained fix PRs.

@honzajavorek honzajavorek merged commit 38e951f into master Mar 24, 2026
13 checks passed
@honzajavorek honzajavorek deleted the honzajavorek/router branch March 24, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-academy Issues related to Web Scraping and Apify academies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Crawlee router in the framework lesson of the JS course

4 participants