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
The information is scraped from the same URL (therefore, the same document).
scrapeMovies selects movie elements, then passes an instance of the resulting cheerio selector to scrapeShowtimes, then scrapeShowtimes is using parent selector tr to find the corresponding movie table row.
Using the parent selector is bad because a scrapeShowtimes should work only on the information it is provided (e.g., the identifier of an element); it shouldn't be capable to iterate the DOM upwards. Furthermore, this makes logging useless.
A better alternative would be to derive a unique selector that can be shared between the processes. The above example could be then rewritten to:
Thats simply for chaining multiple selectors. I guess it could be written as guide.movieElementSelector + '.item-list a[href^="/reservation"]', but that would selector parsing a lot more complicated (because quantifier expression and other expressions could appear anywhere in the selector).
Sometimes different parts of the scraper script need to access the same element.
Consider this example:
scrapeMovies
gets a list of movie names, https://gist.github.com/gajus/68f9da3b27a51a58db990ae67e9acdae#file-mk2-js-L49-L62scrapeShowtimes
parsers additional information about the parsed movies, https://gist.github.com/gajus/68f9da3b27a51a58db990ae67e9acdae#file-mk2-js-L83-L106The information is scraped from the same URL (therefore, the same document).
scrapeMovies
selects movie elements, then passes an instance of the resultingcheerio
selector toscrapeShowtimes
, thenscrapeShowtimes
is using parent selectortr
to find the corresponding movie table row.Using the parent selector is bad because a
scrapeShowtimes
should work only on the information it is provided (e.g., the identifier of an element); it shouldn't be capable to iterate the DOM upwards. Furthermore, this makes logging useless.A better alternative would be to derive a unique selector that can be shared between the processes. The above example could be then rewritten to:
The idea is that
tr::selector()
returns a CSS selector that given the same document will select the same element.The text was updated successfully, but these errors were encountered: