make request for cookies inside createSessionFunction
Dear all, I am trying to use createSessionFunction to create a session and set some basic cookies from a response. The problem is how can I make a request to an endpoint to get a cookies inside createSessionFunction ?
My basic code is this and am wondering what is the best way to get cookies without breaking the flow of the crawler.
createSessionFunction: async(sessionPool,options) => {
const session1 = await sessionPool.getSession();
const proxyurl = await proxyConfigurationEU.newUrl(session1.id);
// Get cookies
session1.setCookiesFromResponse(response);
return session1
}
2 Replies
adverse-sapphire•2y ago
Hi, you can make the request here (for example by using got-scraping: https://github.com/apify/got-scraping) and then set the cookies. Check out also: https://docs.apify.com/academy/api-scraping/general-api-scraping/cookies-headers-tokens
Cookies, headers, and tokens | Apify Documentation
Learn about how some APIs require certain cookies, headers, and/or tokens to be present in a request in order for data to be received.
metropolitan-bronzeOP•2y ago
Hey @lemurio . Yes I am doing the same. But when I try to set the cookies to a sesssion via session.setCookies(). It doesnt set. I dont see the cookies being set in my key value pair.