diff --git a/scrapy_playwright/__init__.py b/scrapy_playwright/__init__.py index 76abcde..ca01193 100644 --- a/scrapy_playwright/__init__.py +++ b/scrapy_playwright/__init__.py @@ -1 +1 @@ -__version__ = "0.0.3501" +__version__ = "0.0.3502" diff --git a/scrapy_playwright/handler.py b/scrapy_playwright/handler.py index 2c5c41d..843b4d4 100644 --- a/scrapy_playwright/handler.py +++ b/scrapy_playwright/handler.py @@ -288,7 +288,7 @@ async def _create_page(self, request: Request, spider: Spider) -> Page: page.on("close", self._make_close_page_callback(context_name)) page.on("crash", self._make_close_page_callback(context_name)) - page.on("request", _make_request_logger(context_name, spider)) + page.on("request", _make_request_logger(context_name, spider, getattr(request, 'playwright_id', None))) page.on("response", _make_response_logger(context_name, spider)) page.on("request", self._increment_request_stats) page.on("response", self._increment_response_stats) @@ -755,15 +755,16 @@ async def _maybe_execute_page_init_callback( raise -def _make_request_logger(context_name: str, spider: Spider) -> Callable: +def _make_request_logger(context_name: str, spider: Spider, playwright_id: str) -> Callable: async def _log_request(request: PlaywrightRequest) -> None: - log_args = [context_name, request.method.upper(), request.url, request.resource_type] + uid = "" if playwright_id is None else f" {playwright_id}" + log_args = [context_name, request.method.upper(), request.url, uid, request.resource_type] referrer = await _get_header_value(request, "referer") if referrer: log_args.append(referrer) - log_msg = "[Context=%s] Request: <%s %s> (resource type: %s, referrer: %s)" + log_msg = "[Context=%s] Request: <%s %s%s> (resource type: %s, referrer: %s)" else: - log_msg = "[Context=%s] Request: <%s %s> (resource type: %s)" + log_msg = "[Context=%s] Request: <%s %s%s> (resource type: %s)" logger.debug( log_msg, *log_args,