Apify Discord Mirror

Updated last year

Passing data to a router/ handler

At a glance

The community member is trying to pass a username and password to the async function in the default handler, as they are using the default handler to log in to a website. They have seen different guides using various input parameters, but are unsure if these are specific to the module. The community members in the comments suggest using the userData option to pass custom data through the crawler.

Useful resources
I'm trying to pass a username and password to the async function in the default handler, since I'm using the default handler to log in to the website. I've seen different guides use all kinds of input parameters - request, page, enqueueLinks, log, pushData - but these seem to all be specific prebuilt parameters of the module? I'm not sure. so, how could I pass my own data through?
L
l
A
3 comments
Use userData option.
Plain Text
router.addHandler('crawler-start', async (ctx) => {
   // Do some stuff with ctx.request.userData
});

crawler.addRequests([{url: 'https://crawlee.dev/',  userData: {label: 'crawler-start', additionalData: 'somObject'}}])
thank you so much!!!!
just advanced to level 1! Thanks for your contributions! πŸŽ‰
Add a reply
Sign up and join the conversation on Discord