(context: PlaywrightCrawlingContext)
| 380 | |
| 381 | @crawler.router.default_handler |
| 382 | async def handler(context: PlaywrightCrawlingContext) -> None: |
| 383 | if not context.session: |
| 384 | return |
| 385 | |
| 386 | sessions_ids.append(context.session.id) |
| 387 | sessions[context.session.id] = context.session |
| 388 | response_data = json.loads(await context.response.text()) |
| 389 | response_cookies[context.session.id] = response_data.get('cookies') |
| 390 | |
| 391 | if context.request.unique_key == '1': |
| 392 | # With the second request, we check the cookies in the session and set retire |
| 393 | await context.add_requests( |
| 394 | [ |
| 395 | Request.from_url( |
| 396 | str(server_url.with_path('/cookies')), unique_key='2', user_data={'retire_session': True} |
| 397 | ) |
| 398 | ] |
| 399 | ) |
| 400 | return |
| 401 | |
| 402 | if context.request.user_data.get('retire_session'): |
| 403 | context.session.retire() |
| 404 | |
| 405 | if context.request.unique_key == '2': |
| 406 | # The third request is made with a new session to make sure it does not use another session's cookies |
| 407 | await context.add_requests([Request.from_url(str(server_url.with_path('/cookies')), unique_key='3')]) |
| 408 | |
| 409 | await crawler.run( |
| 410 | [ |
nothing calls this directly
no test coverage detected