Passing data to a router/ handler

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?
3 Replies
national-gold
national-gold•2y ago
Use userData option.
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'}}])
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'}}])
adverse-sapphire
adverse-sapphireOP•2y ago
thank you so much!!!!
MEE6
MEE6•2y ago
@levav just advanced to level 1! Thanks for your contributions! 🎉

Did you find this page helpful?