Skip to content

Commit 47953f3

Browse files
committed
update
1 parent 2d99b33 commit 47953f3

2 files changed

Lines changed: 5 additions & 18 deletions

File tree

src/crawlee/crawlers/_playwright/_playwright_crawler.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import logging
55
import warnings
66
from datetime import timedelta
7-
from typing import TYPE_CHECKING, Any, Generic, Literal
7+
from functools import partial
8+
from typing import TYPE_CHECKING, Any, Generic, Literal, cast
89

910
import playwright.async_api
1011
from more_itertools import partition
@@ -250,7 +251,7 @@ async def _open_page(
250251
log=context.log,
251252
register_deferred_cleanup=context.register_deferred_cleanup,
252253
page=crawlee_page.page,
253-
block_requests=self._make_block_requests(crawlee_page.page),
254+
block_requests=cast('BlockRequestsFunction', partial(block_requests, page=crawlee_page.page)),
254255
goto_options=GotoOptions(**self._goto_options),
255256
)
256257

@@ -534,7 +535,7 @@ async def _create_crawling_context(
534535
infinite_scroll=lambda: infinite_scroll(context.page),
535536
extract_links=extract_links,
536537
enqueue_links=self._create_enqueue_links_function(context, extract_links),
537-
block_requests=self._make_block_requests(context.page),
538+
block_requests=cast('BlockRequestsFunction', partial(block_requests, page=context.page)),
538539
)
539540

540541
if context.session:
@@ -557,18 +558,6 @@ def post_navigation_hook(self, hook: Callable[[PlaywrightPostNavCrawlingContext]
557558
"""
558559
self._post_navigation_hooks.append(hook)
559560

560-
@staticmethod
561-
def _make_block_requests(page: Page) -> BlockRequestsFunction:
562-
"""Build a `BlockRequestsFunction` bound to the given page."""
563-
564-
async def _bound_block_requests(
565-
url_patterns: list[str] | None = None,
566-
extra_url_patterns: list[str] | None = None,
567-
) -> None:
568-
await block_requests(page, url_patterns=url_patterns, extra_url_patterns=extra_url_patterns)
569-
570-
return _bound_block_requests
571-
572561
async def _get_cookies(self, page: Page) -> list[PlaywrightCookieParam]:
573562
"""Get the cookies from the page."""
574563
cookies = await page.context.cookies()

tests/unit/crawlers/_adaptive_playwright/test_adaptive_playwright_crawler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
from crawlee.crawlers._adaptive_playwright._adaptive_playwright_crawler_statistics import (
2828
AdaptivePlaywrightCrawlerStatisticState,
2929
)
30-
from crawlee.crawlers._adaptive_playwright._adaptive_playwright_crawling_context import (
31-
AdaptiveContextError,
32-
)
30+
from crawlee.crawlers._adaptive_playwright._adaptive_playwright_crawling_context import AdaptiveContextError
3331
from crawlee.sessions import SessionPool
3432
from crawlee.statistics import Statistics
3533
from crawlee.storage_clients import SqlStorageClient

0 commit comments

Comments
 (0)