Skip to content

Commit

Permalink
v0.0.3502
Browse files Browse the repository at this point in the history
  • Loading branch information
sanzenwin committed Jun 3, 2024
1 parent 53aee32 commit bf6d93b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scrapy_playwright/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.3501"
__version__ = "0.0.3502"
11 changes: 6 additions & 5 deletions scrapy_playwright/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bf6d93b

Please sign in to comment.