drogbata
09/21/2025, 9:05 PMAnswer Overflow
09/21/2025, 9:05 PMMantisus
09/22/2025, 5:30 PMSessionCookies are tied to a specific Session.
I think you are checking SessionCookies in another Session when you check this.
You can either limit SessionPool to 1 session. Or store cookies in some external variable and pass cookies to each Session, for example, in pre_navigation_hook.
Documentation that may be useful to you
https://crawlee.dev/python/docs/guides/logging-in-with-a-crawler
https://crawlee.dev/python/docs/guides/session-managementdrogbata
09/23/2025, 6:33 AMMantisus
09/24/2025, 4:54 AMMantisus
09/24/2025, 6:55 AMpython
async def test():
crawler = BeautifulSoupCrawler()
@crawler.router.default_handler
async def set_cookies(ctx: BeautifulSoupCrawlingContext):
ctx.log.info(f'Cookies set to {ctx.session.id}')
await ctx.add_requests([Request.from_url('https://httpbin.org/cookies', label='GET', session_id=ctx.session.id)])
@crawler.router.handler('GET')
async def get_cookies(ctx: BeautifulSoupCrawlingContext):
ctx.log.info(f'Cookies retrieved from {ctx.session.id}')
print(ctx.session.cookies)
print(ctx.http_response.read())
await crawler.run(['https://httpbin.org/cookies/set/a/1'])