refactor: change Academy code examples to use Crawlee router#2293
refactor: change Academy code examples to use Crawlee router#2293honzajavorek wants to merge 1 commit intomasterfrom
Conversation
Fix #2181 Address #2097 (comment) by @B4nan
|
Preview for this PR was built for commit |
There was a problem hiding this comment.
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 labeledaddHandler()routes. - Refactor
crawlee_f1_drivers.mjsandcrawlee_netflix_ratings.mjsexercise 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. |
sources/academy/webscraping/scraping_basics_javascript/exercises/crawlee_f1_drivers.mjs
Show resolved
Hide resolved
sources/academy/webscraping/scraping_basics_javascript/exercises/crawlee_netflix_ratings.mjs
Show resolved
Hide resolved
sources/academy/webscraping/scraping_basics_javascript/exercises/crawlee_netflix_ratings.mjs
Show resolved
Hide resolved
|
Preview for this PR was built for commit |
B4nan
left a comment
There was a problem hiding this comment.
did you change the indents on purpose? (4 -> 2 spaces)
| const $variants = $(".product-form__option.no-js option"); | ||
| if ($variants.length === 0) { | ||
| // highlight-next-line | ||
| pushData(item); |
| for (const element of $variants.toArray()) { | ||
| const variant = parseVariant($(element)); | ||
| // highlight-next-line | ||
| pushData({ ...item, ...variant }); |
| if ($variants.length === 0) { | ||
| // highlight-next-line | ||
| log.info('Saving a product'); | ||
| pushData(item); |
| const variant = parseVariant($(element)); | ||
| // highlight-next-line | ||
| log.info('Saving a product variant'); | ||
| pushData({ ...item, ...variant }); |
5ff2b51 to
41d7ed0
Compare
|
Preview for this PR was built for commit |
41d7ed0 to
1aa2eb6
Compare
|
Preview for this PR was built for commit |
Fix #2181, address #2097 (comment) by @B4nan
Note
Low Risk
Low risk documentation/exercise refactor that changes sample code structure to the newer Crawlee
routerAPI without altering the scraping behavior.Overview
Refactors the Crawlee lesson (
12_framework.md) to constructCheerioCrawlerwithout an inlinerequestHandlerand instead register routing viacrawler.router.addDefaultHandler()plus labeledaddHandler()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, removingrequest.labelbranching 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.