Karim shoair commited on
Commit ·
7d2ea72
1
Parent(s): 73f9191
fix: make browser fetchers type hints always present
Browse files
scrapling/engines/_browsers/_types.py
CHANGED
|
@@ -19,7 +19,6 @@ from scrapling.core._types import (
|
|
| 19 |
TypeAlias,
|
| 20 |
SetCookieParam,
|
| 21 |
SelectorWaitStates,
|
| 22 |
-
TYPE_CHECKING,
|
| 23 |
)
|
| 24 |
from scrapling.engines.toolbelt.proxy_rotation import ProxyRotator
|
| 25 |
|
|
@@ -27,97 +26,93 @@ from scrapling.engines.toolbelt.proxy_rotation import ProxyRotator
|
|
| 27 |
ImpersonateType: TypeAlias = BrowserTypeLiteral | List[BrowserTypeLiteral] | None
|
| 28 |
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
PlaywrightSession = TypedDict
|
| 121 |
-
PlaywrightFetchParams = TypedDict
|
| 122 |
-
StealthSession = TypedDict
|
| 123 |
-
StealthFetchParams = TypedDict
|
|
|
|
| 19 |
TypeAlias,
|
| 20 |
SetCookieParam,
|
| 21 |
SelectorWaitStates,
|
|
|
|
| 22 |
)
|
| 23 |
from scrapling.engines.toolbelt.proxy_rotation import ProxyRotator
|
| 24 |
|
|
|
|
| 26 |
ImpersonateType: TypeAlias = BrowserTypeLiteral | List[BrowserTypeLiteral] | None
|
| 27 |
|
| 28 |
|
| 29 |
+
# Types for session initialization
|
| 30 |
+
class RequestsSession(TypedDict, total=False):
|
| 31 |
+
impersonate: ImpersonateType
|
| 32 |
+
http3: Optional[bool]
|
| 33 |
+
stealthy_headers: Optional[bool]
|
| 34 |
+
proxies: Optional[ProxySpec]
|
| 35 |
+
proxy: Optional[str]
|
| 36 |
+
proxy_auth: Optional[Tuple[str, str]]
|
| 37 |
+
proxy_rotator: Optional[ProxyRotator]
|
| 38 |
+
timeout: Optional[int | float]
|
| 39 |
+
headers: Optional[Mapping[str, Optional[str]]]
|
| 40 |
+
retries: Optional[int]
|
| 41 |
+
retry_delay: Optional[int]
|
| 42 |
+
follow_redirects: Optional[bool]
|
| 43 |
+
max_redirects: Optional[int]
|
| 44 |
+
verify: Optional[bool]
|
| 45 |
+
cert: Optional[str | Tuple[str, str]]
|
| 46 |
+
selector_config: Optional[Dict]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# Types for GET request method parameters
|
| 50 |
+
class GetRequestParams(RequestsSession, total=False):
|
| 51 |
+
params: Optional[Dict | List | Tuple]
|
| 52 |
+
cookies: Optional[CookieTypes]
|
| 53 |
+
auth: Optional[Tuple[str, str]]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# Types for POST/PUT/DELETE request method parameters
|
| 57 |
+
class DataRequestParams(GetRequestParams, total=False):
|
| 58 |
+
data: Optional[Dict[str, str] | List[Tuple] | str | BytesIO | bytes]
|
| 59 |
+
json: Optional[Dict | List]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# Types for browser session
|
| 63 |
+
class PlaywrightSession(TypedDict, total=False):
|
| 64 |
+
max_pages: int
|
| 65 |
+
headless: bool
|
| 66 |
+
disable_resources: bool
|
| 67 |
+
network_idle: bool
|
| 68 |
+
load_dom: bool
|
| 69 |
+
wait_selector: Optional[str]
|
| 70 |
+
wait_selector_state: SelectorWaitStates
|
| 71 |
+
cookies: Sequence[SetCookieParam] | None
|
| 72 |
+
google_search: bool
|
| 73 |
+
wait: int | float
|
| 74 |
+
timezone_id: str | None
|
| 75 |
+
page_action: Optional[Callable]
|
| 76 |
+
proxy: Optional[str | Dict[str, str] | Tuple]
|
| 77 |
+
proxy_rotator: Optional[ProxyRotator]
|
| 78 |
+
extra_headers: Optional[Dict[str, str]]
|
| 79 |
+
timeout: int | float
|
| 80 |
+
init_script: Optional[str]
|
| 81 |
+
user_data_dir: str
|
| 82 |
+
selector_config: Optional[Dict]
|
| 83 |
+
additional_args: Optional[Dict]
|
| 84 |
+
locale: Optional[str]
|
| 85 |
+
real_chrome: bool
|
| 86 |
+
cdp_url: Optional[str]
|
| 87 |
+
useragent: Optional[str]
|
| 88 |
+
extra_flags: Optional[List[str]]
|
| 89 |
+
blocked_domains: Optional[Set[str]]
|
| 90 |
+
retries: int
|
| 91 |
+
retry_delay: int | float
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class PlaywrightFetchParams(TypedDict, total=False):
|
| 95 |
+
load_dom: bool
|
| 96 |
+
wait: int | float
|
| 97 |
+
network_idle: bool
|
| 98 |
+
google_search: bool
|
| 99 |
+
timeout: int | float
|
| 100 |
+
disable_resources: bool
|
| 101 |
+
wait_selector: Optional[str]
|
| 102 |
+
page_action: Optional[Callable]
|
| 103 |
+
selector_config: Optional[Dict]
|
| 104 |
+
extra_headers: Optional[Dict[str, str]]
|
| 105 |
+
wait_selector_state: SelectorWaitStates
|
| 106 |
+
blocked_domains: Optional[Set[str]]
|
| 107 |
+
proxy: Optional[str | Dict[str, str]]
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
class StealthSession(PlaywrightSession, total=False):
|
| 111 |
+
allow_webgl: bool
|
| 112 |
+
hide_canvas: bool
|
| 113 |
+
block_webrtc: bool
|
| 114 |
+
solve_cloudflare: bool
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
class StealthFetchParams(PlaywrightFetchParams, total=False):
|
| 118 |
+
solve_cloudflare: bool
|
|
|
|
|
|
|
|
|
|
|
|