quickest-silver•2y ago
Set cookies with cheerio
I switched from playwright to cheerio because of familiarity and cannot figure out how to set cookies (specifically for auth).
In playwright I did
ontext.page.context().addCookies
. How do I do this in cheerio?2 Replies
One option is to simply add them to
request.headers
as cookie
string either during enqueueing or preNavigationHooks.
Second option is to do it through session as session.setCookies
https://crawlee.dev/api/core/class/Session#setCookies. This needs to be done in preNavigationHooks
because you don't have the attached session in enqueueing yetSession | API | Crawlee
Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions.
You can imagine each session as a specific user, with its own cookies, IP (via proxy) and potentially a unique browser fingerprint.
Session internal state can be enriched with custom user data for example some authorization toke...
quickest-silverOP•2y ago
That's what I was looking for, thanks!