Skip to content

🕷️ The BEST Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev

style: Using keywords for validation

Karim shoairadb82008e510
diff --git a/scrapling/engines/_browsers/_base.py b/scrapling/engines/_browsers/_base.py
index 6b91d8f..e27591f 100644
--- a/scrapling/engines/_browsers/_base.py
+++ b/scrapling/engines/_browsers/_base.py
@@ -144,56 +144,8 @@ class AsyncSession(SyncSession):
class DynamicSessionMixin:
- def __validate__(
- self,
- __max_pages,
- headless,
- google_search,
- hide_canvas,
- disable_webgl,
- real_chrome,
- stealth,
- wait,
- page_action,
- proxy,
- locale,
- extra_headers,
- useragent,
- cdp_url,
- timeout,
- disable_resources,
- wait_selector,
- init_script,
- cookies,
- network_idle,
- wait_selector_state,
- selector_config,
- ):
- params = {
- "max_pages": __max_pages,
- "headless": headless,
- "google_search": google_search,
- "hide_canvas": hide_canvas,
- "disable_webgl": disable_webgl,
- "real_chrome": real_chrome,
- "stealth": stealth,
- "wait": wait,
- "page_action": page_action,
- "proxy": proxy,
- "locale": locale,
- "extra_headers": extra_headers,
- "useragent": useragent,
- "timeout": timeout,
- "selector_config": selector_config,
- "disable_resources": disable_resources,
- "wait_selector": wait_selector,
- "init_script": init_script,
- "cookies": cookies,
- "network_idle": network_idle,
- "wait_selector_state": wait_selector_state,
- "cdp_url": cdp_url,
- }
- config = validate(params, PlaywrightConfig)
+ def __validate__(self, **params):
+ config = validate(**params, model=PlaywrightConfig)
self.max_pages = config.max_pages
self.headless = config.headless
@@ -268,62 +220,8 @@ class DynamicSessionMixin:
class StealthySessionMixin:
- def __validate__(
- self,
- max_pages,
- headless,
- block_images,
- disable_resources,
- block_webrtc,
- allow_webgl,
- network_idle,
- humanize,
- solve_cloudflare,
- wait,
- timeout,
- page_action,
- wait_selector,
- init_script,
- addons,
- wait_selector_state,
- cookies,
- google_search,
- extra_headers,
- proxy,
- os_randomize,
- disable_ads,
- geoip,
- selector_config,
- additional_args,
- ):
- params = {
- "max_pages": max_pages,
- "headless": headless,
- "block_images": block_images,
- "disable_resources": disable_resources,
- "block_webrtc": block_webrtc,
- "allow_webgl": allow_webgl,
- "network_idle": network_idle,
- "humanize": humanize,
- "solve_cloudflare": solve_cloudflare,
- "wait": wait,
- "timeout": timeout,
- "page_action": page_action,
- "wait_selector": wait_selector,
- "init_script": init_script,
- "addons": addons,
- "wait_selector_state": wait_selector_state,
- "cookies": cookies,
- "google_search": google_search,
- "extra_headers": extra_headers,
- "proxy": proxy,
- "os_randomize": os_randomize,
- "disable_ads": disable_ads,
- "geoip": geoip,
- "selector_config": selector_config,
- "additional_args": additional_args,
- }
- config = validate(params, CamoufoxConfig)
+ def __validate__(self, **params):
+ config = validate(**params, model=CamoufoxConfig)
self.max_pages = config.max_pages
self.headless = config.headless
diff --git a/scrapling/engines/_browsers/_camoufox.py b/scrapling/engines/_browsers/_camoufox.py
index 87526ef..3412fd6 100644
--- a/scrapling/engines/_browsers/_camoufox.py
+++ b/scrapling/engines/_browsers/_camoufox.py
@@ -133,31 +133,31 @@ class StealthySession(StealthySessionMixin, SyncSession):
"""
self.__validate__(
- __max_pages,
- headless,
- block_images,
- disable_resources,
- block_webrtc,
- allow_webgl,
- network_idle,
- humanize,
- solve_cloudflare,
- wait,
- timeout,
- page_action,
- wait_selector,
- init_script,
- addons,
- wait_selector_state,
- cookies,
- google_search,
- extra_headers,
- proxy,
- os_randomize,
- disable_ads,
- geoip,
- selector_config,
- additional_args,
+ wait=wait,
+ proxy=proxy,
+ geoip=geoip,
+ addons=addons,
+ timeout=timeout,
+ cookies=cookies,
+ headless=headless,
+ humanize=humanize,
+ max_pages=__max_pages,
+ disable_ads=disable_ads,
+ allow_webgl=allow_webgl,
+ page_action=page_action,
+ init_script=init_script,
+ network_idle=network_idle,
+ block_images=block_images,
+ block_webrtc=block_webrtc,
+ os_randomize=os_randomize,
+ wait_selector=wait_selector,
+ google_search=google_search,
+ extra_headers=extra_headers,
+ additional_args=additional_args,
+ selector_config=selector_config,
+ solve_cloudflare=solve_cloudflare,
+ disable_resources=disable_resources,
+ wait_selector_state=wait_selector_state,
)
super().__init__(max_pages=self.max_pages)
@@ -447,31 +447,31 @@ class AsyncStealthySession(StealthySessionMixin, AsyncSession):
:param additional_args: Additional arguments to be passed to Camoufox as additional settings, and it takes higher priority than Scrapling's settings.
"""
self.__validate__(
- max_pages,
- headless,
- block_images,
- disable_resources,
- block_webrtc,
- allow_webgl,
- network_idle,
- humanize,
- solve_cloudflare,
- wait,
- timeout,
- page_action,
- wait_selector,
- init_script,
- addons,
- wait_selector_state,
- cookies,
- google_search,
- extra_headers,
- proxy,
- os_randomize,
- disable_ads,
- geoip,
- selector_config,
- additional_args,
+ wait=wait,
+ proxy=proxy,
+ geoip=geoip,
+ addons=addons,
+ timeout=timeout,
+ cookies=cookies,
+ headless=headless,
+ humanize=humanize,
+ max_pages=max_pages,
+ disable_ads=disable_ads,
+ allow_webgl=allow_webgl,
+ page_action=page_action,
+ init_script=init_script,
+ network_idle=network_idle,
+ block_images=block_images,
+ block_webrtc=block_webrtc,
+ os_randomize=os_randomize,
+ wait_selector=wait_selector,
+ google_search=google_search,
+ extra_headers=extra_headers,
+ additional_args=additional_args,
+ selector_config=selector_config,
+ solve_cloudflare=solve_cloudflare,
+ disable_resources=disable_resources,
+ wait_selector_state=wait_selector_state,
)
super().__init__(max_pages=self.max_pages)
diff --git a/scrapling/engines/_browsers/_controllers.py b/scrapling/engines/_browsers/_controllers.py
index d4f238f..49f6c9d 100644
--- a/scrapling/engines/_browsers/_controllers.py
+++ b/scrapling/engines/_browsers/_controllers.py
@@ -122,28 +122,28 @@ class DynamicSession(DynamicSessionMixin, SyncSession):
:param selector_config: The arguments that will be passed in the end while creating the final Selector's class.
"""
self.__validate__(
- __max_pages,
- headless,
- google_search,
- hide_canvas,
- disable_webgl,
- real_chrome,
- stealth,
- wait,
- page_action,
- proxy,
- locale,
- extra_headers,
- useragent,
- cdp_url,
- timeout,
- disable_resources,
- wait_selector,
- init_script,
- cookies,
- network_idle,
- wait_selector_state,
- selector_config,
+ wait=wait,
+ proxy=proxy,
+ locale=locale,
+ timeout=timeout,
+ stealth=stealth,
+ cdp_url=cdp_url,
+ cookies=cookies,
+ headless=headless,
+ useragent=useragent,
+ max_pages=__max_pages,
+ real_chrome=real_chrome,
+ page_action=page_action,
+ hide_canvas=hide_canvas,
+ init_script=init_script,
+ network_idle=network_idle,
+ google_search=google_search,
+ extra_headers=extra_headers,
+ wait_selector=wait_selector,
+ disable_webgl=disable_webgl,
+ selector_config=selector_config,
+ disable_resources=disable_resources,
+ wait_selector_state=wait_selector_state,
)
super().__init__(max_pages=self.max_pages)
@@ -378,28 +378,28 @@ class AsyncDynamicSession(DynamicSessionMixin, AsyncSession):
"""
self.__validate__(
- max_pages,
- headless,
- google_search,
- hide_canvas,
- disable_webgl,
- real_chrome,
- stealth,
- wait,
- page_action,
- proxy,
- locale,
- extra_headers,
- useragent,
- cdp_url,
- timeout,
- disable_resources,
- wait_selector,
- init_script,
- cookies,
- network_idle,
- wait_selector_state,
- selector_config,
+ wait=wait,
+ proxy=proxy,
+ locale=locale,
+ timeout=timeout,
+ stealth=stealth,
+ cdp_url=cdp_url,
+ cookies=cookies,
+ headless=headless,
+ useragent=useragent,
+ max_pages=max_pages,
+ real_chrome=real_chrome,
+ page_action=page_action,
+ hide_canvas=hide_canvas,
+ init_script=init_script,
+ network_idle=network_idle,
+ google_search=google_search,
+ extra_headers=extra_headers,
+ wait_selector=wait_selector,
+ disable_webgl=disable_webgl,
+ selector_config=selector_config,
+ disable_resources=disable_resources,
+ wait_selector_state=wait_selector_state,
)
super().__init__(max_pages=self.max_pages)