SOLVED: enqueueLinks not working properly

hey, i'm trying to crawl a website, and i use the enqueueLinks() function which is supposedly context-aware. however, when i call await enqueueLinks() at the bottom of my request handler (i can confirm it is actually IN the request handler), it gives me this error:
enqueueLinks() was called without the required options. You can only do that when you use the `crawlingContext.enqueueLinks()` method in request handlers.
enqueueLinks() was called without the required options. You can only do that when you use the `crawlingContext.enqueueLinks()` method in request handlers.
anyone have any idea what's going on?
2 Replies
deep-jade
deep-jadeOP2y ago
UPDATE: thanks to @shovelandsandbox, i have figured the root of the problem. when you want to use enqueueLinks() inside a request handler, you have to destructure it, too. also, make sure that enqueueLinks is not imported! here's what @shovelandsandbox wrote:
router.addHandler(ROUTE_HANDLERS.PAGE_DETAILS, async ({ $, request, log, enqueueLinks /* <- added to destructuring here */ }) => {
// body of route handler
try {
await enqueueLinks()
} catch (error) {
log.error('failed to enqueue links', error)
}
})
router.addHandler(ROUTE_HANDLERS.PAGE_DETAILS, async ({ $, request, log, enqueueLinks /* <- added to destructuring here */ }) => {
// body of route handler
try {
await enqueueLinks()
} catch (error) {
log.error('failed to enqueue links', error)
}
})
previously, i was running the request handler with just { $, request } destructured. again, thank you to @shovelandsandbox for helping me solve this, as this will probably help many others who are likely to face this problem.
notable-maroon
notable-maroon2y ago

Did you find this page helpful?