scrapling 0.3.5__py3-none-any.whl → 0.3.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scrapling/__init__.py +29 -19
- scrapling/cli.py +21 -4
- scrapling/core/_types.py +3 -2
- scrapling/core/ai.py +24 -15
- scrapling/core/custom_types.py +20 -27
- scrapling/core/mixins.py +15 -9
- scrapling/core/shell.py +6 -4
- scrapling/core/storage.py +7 -6
- scrapling/core/translator.py +13 -8
- scrapling/core/utils/__init__.py +0 -1
- scrapling/engines/_browsers/__init__.py +0 -2
- scrapling/engines/_browsers/_base.py +45 -21
- scrapling/engines/_browsers/_camoufox.py +98 -43
- scrapling/engines/_browsers/_config_tools.py +1 -1
- scrapling/engines/_browsers/_controllers.py +34 -13
- scrapling/engines/_browsers/_validators.py +31 -10
- scrapling/engines/constants.py +0 -15
- scrapling/engines/static.py +749 -336
- scrapling/engines/toolbelt/convertor.py +13 -15
- scrapling/engines/toolbelt/custom.py +6 -9
- scrapling/engines/toolbelt/fingerprints.py +17 -10
- scrapling/engines/toolbelt/navigation.py +11 -3
- scrapling/fetchers/__init__.py +46 -0
- scrapling/fetchers/chrome.py +210 -0
- scrapling/fetchers/firefox.py +212 -0
- scrapling/fetchers/requests.py +28 -0
- scrapling/parser.py +109 -84
- {scrapling-0.3.5.dist-info → scrapling-0.3.7.dist-info}/METADATA +17 -16
- scrapling-0.3.7.dist-info/RECORD +47 -0
- scrapling/fetchers.py +0 -444
- scrapling-0.3.5.dist-info/RECORD +0 -44
- {scrapling-0.3.5.dist-info → scrapling-0.3.7.dist-info}/WHEEL +0 -0
- {scrapling-0.3.5.dist-info → scrapling-0.3.7.dist-info}/entry_points.txt +0 -0
- {scrapling-0.3.5.dist-info → scrapling-0.3.7.dist-info}/licenses/LICENSE +0 -0
- {scrapling-0.3.5.dist-info → scrapling-0.3.7.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,212 @@
|
|
1
|
+
from scrapling.core._types import (
|
2
|
+
Callable,
|
3
|
+
Dict,
|
4
|
+
List,
|
5
|
+
Optional,
|
6
|
+
SelectorWaitStates,
|
7
|
+
)
|
8
|
+
from scrapling.engines.toolbelt.custom import BaseFetcher, Response
|
9
|
+
from scrapling.engines._browsers._camoufox import StealthySession, AsyncStealthySession
|
10
|
+
|
11
|
+
|
12
|
+
class StealthyFetcher(BaseFetcher):
|
13
|
+
"""A `Fetcher` class type that is a completely stealthy fetcher that uses a modified version of Firefox.
|
14
|
+
|
15
|
+
It works as real browsers passing almost all online tests/protections based on Camoufox.
|
16
|
+
Other added flavors include setting the faked OS fingerprints to match the user's OS, and the referer of every request is set as if this request came from Google's search of this URL's domain.
|
17
|
+
"""
|
18
|
+
|
19
|
+
@classmethod
|
20
|
+
def fetch(
|
21
|
+
cls,
|
22
|
+
url: str,
|
23
|
+
headless: bool = True, # noqa: F821
|
24
|
+
block_images: bool = False,
|
25
|
+
disable_resources: bool = False,
|
26
|
+
block_webrtc: bool = False,
|
27
|
+
allow_webgl: bool = True,
|
28
|
+
network_idle: bool = False,
|
29
|
+
load_dom: bool = True,
|
30
|
+
humanize: bool | float = True,
|
31
|
+
solve_cloudflare: bool = False,
|
32
|
+
wait: int | float = 0,
|
33
|
+
timeout: int | float = 30000,
|
34
|
+
page_action: Optional[Callable] = None,
|
35
|
+
wait_selector: Optional[str] = None,
|
36
|
+
init_script: Optional[str] = None,
|
37
|
+
addons: Optional[List[str]] = None,
|
38
|
+
wait_selector_state: SelectorWaitStates = "attached",
|
39
|
+
cookies: Optional[List[Dict]] = None,
|
40
|
+
google_search: bool = True,
|
41
|
+
extra_headers: Optional[Dict[str, str]] = None,
|
42
|
+
proxy: Optional[str | Dict[str, str]] = None,
|
43
|
+
os_randomize: bool = False,
|
44
|
+
disable_ads: bool = False,
|
45
|
+
geoip: bool = False,
|
46
|
+
custom_config: Optional[Dict] = None,
|
47
|
+
additional_args: Optional[Dict] = None,
|
48
|
+
) -> Response:
|
49
|
+
"""
|
50
|
+
Opens up a browser and do your request based on your chosen options below.
|
51
|
+
|
52
|
+
:param url: Target url.
|
53
|
+
:param headless: Run the browser in headless/hidden (default), or headful/visible mode.
|
54
|
+
:param block_images: Prevent the loading of images through Firefox preferences.
|
55
|
+
This can help save your proxy usage but be careful with this option as it makes some websites never finish loading.
|
56
|
+
:param disable_resources: Drop requests of unnecessary resources for a speed boost. It depends, but it made requests ~25% faster in my tests for some websites.
|
57
|
+
Requests dropped are of type `font`, `image`, `media`, `beacon`, `object`, `imageset`, `texttrack`, `websocket`, `csp_report`, and `stylesheet`.
|
58
|
+
This can help save your proxy usage but be careful with this option as it makes some websites never finish loading.
|
59
|
+
:param block_webrtc: Blocks WebRTC entirely.
|
60
|
+
:param cookies: Set cookies for the next request.
|
61
|
+
:param addons: List of Firefox addons to use. Must be paths to extracted addons.
|
62
|
+
:param humanize: Humanize the cursor movement. Takes either True or the MAX duration in seconds of the cursor movement. The cursor typically takes up to 1.5 seconds to move across the window.
|
63
|
+
:param solve_cloudflare: Solves all types of the Cloudflare's Turnstile/Interstitial challenges before returning the response to you.
|
64
|
+
:param allow_webgl: Enabled by default. Disabling WebGL is not recommended as many WAFs now check if WebGL is enabled.
|
65
|
+
:param network_idle: Wait for the page until there are no network connections for at least 500 ms.
|
66
|
+
:param load_dom: Enabled by default, wait for all JavaScript on page(s) to fully load and execute.
|
67
|
+
:param disable_ads: Disabled by default, this installs the `uBlock Origin` addon on the browser if enabled.
|
68
|
+
:param os_randomize: If enabled, Scrapling will randomize the OS fingerprints used. The default is Scrapling matching the fingerprints with the current OS.
|
69
|
+
:param wait: The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the ` Response ` object.
|
70
|
+
:param timeout: The timeout in milliseconds that is used in all operations and waits through the page. The default is 30,000
|
71
|
+
:param page_action: Added for automation. A function that takes the `page` object and does the automation you need.
|
72
|
+
:param wait_selector: Wait for a specific CSS selector to be in a specific state.
|
73
|
+
:param init_script: An absolute path to a JavaScript file to be executed on page creation with this request.
|
74
|
+
:param geoip: Recommended to use with proxies; Automatically use IP's longitude, latitude, timezone, country, locale, and spoof the WebRTC IP address.
|
75
|
+
It will also calculate and spoof the browser's language based on the distribution of language speakers in the target region.
|
76
|
+
:param wait_selector_state: The state to wait for the selector given with `wait_selector`. The default state is `attached`.
|
77
|
+
:param google_search: Enabled by default, Scrapling will set the referer header to be as if this request came from a Google search of this website's domain name.
|
78
|
+
:param extra_headers: A dictionary of extra headers to add to the request. _The referer set by the `google_search` argument takes priority over the referer set here if used together._
|
79
|
+
:param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
|
80
|
+
:param custom_config: A dictionary of custom parser arguments to use with this request. Any argument passed will override any class parameters values.
|
81
|
+
:param additional_args: Additional arguments to be passed to Camoufox as additional settings, and it takes higher priority than Scrapling's settings.
|
82
|
+
:return: A `Response` object.
|
83
|
+
"""
|
84
|
+
if not custom_config:
|
85
|
+
custom_config = {}
|
86
|
+
|
87
|
+
with StealthySession(
|
88
|
+
wait=wait,
|
89
|
+
proxy=proxy,
|
90
|
+
geoip=geoip,
|
91
|
+
addons=addons,
|
92
|
+
timeout=timeout,
|
93
|
+
cookies=cookies,
|
94
|
+
headless=headless,
|
95
|
+
humanize=humanize,
|
96
|
+
load_dom=load_dom,
|
97
|
+
disable_ads=disable_ads,
|
98
|
+
allow_webgl=allow_webgl,
|
99
|
+
page_action=page_action,
|
100
|
+
init_script=init_script,
|
101
|
+
network_idle=network_idle,
|
102
|
+
block_images=block_images,
|
103
|
+
block_webrtc=block_webrtc,
|
104
|
+
os_randomize=os_randomize,
|
105
|
+
wait_selector=wait_selector,
|
106
|
+
google_search=google_search,
|
107
|
+
extra_headers=extra_headers,
|
108
|
+
solve_cloudflare=solve_cloudflare,
|
109
|
+
disable_resources=disable_resources,
|
110
|
+
wait_selector_state=wait_selector_state,
|
111
|
+
selector_config={**cls._generate_parser_arguments(), **custom_config},
|
112
|
+
additional_args=additional_args or {},
|
113
|
+
) as engine:
|
114
|
+
return engine.fetch(url)
|
115
|
+
|
116
|
+
@classmethod
|
117
|
+
async def async_fetch(
|
118
|
+
cls,
|
119
|
+
url: str,
|
120
|
+
headless: bool = True, # noqa: F821
|
121
|
+
block_images: bool = False,
|
122
|
+
disable_resources: bool = False,
|
123
|
+
block_webrtc: bool = False,
|
124
|
+
allow_webgl: bool = True,
|
125
|
+
network_idle: bool = False,
|
126
|
+
load_dom: bool = True,
|
127
|
+
humanize: bool | float = True,
|
128
|
+
solve_cloudflare: bool = False,
|
129
|
+
wait: int | float = 0,
|
130
|
+
timeout: int | float = 30000,
|
131
|
+
page_action: Optional[Callable] = None,
|
132
|
+
wait_selector: Optional[str] = None,
|
133
|
+
init_script: Optional[str] = None,
|
134
|
+
addons: Optional[List[str]] = None,
|
135
|
+
wait_selector_state: SelectorWaitStates = "attached",
|
136
|
+
cookies: Optional[List[Dict]] = None,
|
137
|
+
google_search: bool = True,
|
138
|
+
extra_headers: Optional[Dict[str, str]] = None,
|
139
|
+
proxy: Optional[str | Dict[str, str]] = None,
|
140
|
+
os_randomize: bool = False,
|
141
|
+
disable_ads: bool = False,
|
142
|
+
geoip: bool = False,
|
143
|
+
custom_config: Optional[Dict] = None,
|
144
|
+
additional_args: Optional[Dict] = None,
|
145
|
+
) -> Response:
|
146
|
+
"""
|
147
|
+
Opens up a browser and do your request based on your chosen options below.
|
148
|
+
|
149
|
+
:param url: Target url.
|
150
|
+
:param headless: Run the browser in headless/hidden (default), or headful/visible mode.
|
151
|
+
:param block_images: Prevent the loading of images through Firefox preferences.
|
152
|
+
This can help save your proxy usage but be careful with this option as it makes some websites never finish loading.
|
153
|
+
:param disable_resources: Drop requests of unnecessary resources for a speed boost. It depends, but it made requests ~25% faster in my tests for some websites.
|
154
|
+
Requests dropped are of type `font`, `image`, `media`, `beacon`, `object`, `imageset`, `texttrack`, `websocket`, `csp_report`, and `stylesheet`.
|
155
|
+
This can help save your proxy usage but be careful with this option as it makes some websites never finish loading.
|
156
|
+
:param block_webrtc: Blocks WebRTC entirely.
|
157
|
+
:param cookies: Set cookies for the next request.
|
158
|
+
:param addons: List of Firefox addons to use. Must be paths to extracted addons.
|
159
|
+
:param humanize: Humanize the cursor movement. Takes either True or the MAX duration in seconds of the cursor movement. The cursor typically takes up to 1.5 seconds to move across the window.
|
160
|
+
:param solve_cloudflare: Solves all types of the Cloudflare's Turnstile/Interstitial challenges before returning the response to you.
|
161
|
+
:param allow_webgl: Enabled by default. Disabling WebGL is not recommended as many WAFs now check if WebGL is enabled.
|
162
|
+
:param network_idle: Wait for the page until there are no network connections for at least 500 ms.
|
163
|
+
:param load_dom: Enabled by default, wait for all JavaScript on page(s) to fully load and execute.
|
164
|
+
:param disable_ads: Disabled by default, this installs the `uBlock Origin` addon on the browser if enabled.
|
165
|
+
:param os_randomize: If enabled, Scrapling will randomize the OS fingerprints used. The default is Scrapling matching the fingerprints with the current OS.
|
166
|
+
:param wait: The time (milliseconds) the fetcher will wait after everything finishes before closing the page and returning the ` Response ` object.
|
167
|
+
:param timeout: The timeout in milliseconds that is used in all operations and waits through the page. The default is 30,000
|
168
|
+
:param page_action: Added for automation. A function that takes the `page` object and does the automation you need.
|
169
|
+
:param wait_selector: Wait for a specific CSS selector to be in a specific state.
|
170
|
+
:param init_script: An absolute path to a JavaScript file to be executed on page creation with this request.
|
171
|
+
:param geoip: Recommended to use with proxies; Automatically use IP's longitude, latitude, timezone, country, locale, and spoof the WebRTC IP address.
|
172
|
+
It will also calculate and spoof the browser's language based on the distribution of language speakers in the target region.
|
173
|
+
:param wait_selector_state: The state to wait for the selector given with `wait_selector`. The default state is `attached`.
|
174
|
+
:param google_search: Enabled by default, Scrapling will set the referer header to be as if this request came from a Google search of this website's domain name.
|
175
|
+
:param extra_headers: A dictionary of extra headers to add to the request. _The referer set by the `google_search` argument takes priority over the referer set here if used together._
|
176
|
+
:param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
|
177
|
+
:param custom_config: A dictionary of custom parser arguments to use with this request. Any argument passed will override any class parameters values.
|
178
|
+
:param additional_args: Additional arguments to be passed to Camoufox as additional settings, and it takes higher priority than Scrapling's settings.
|
179
|
+
:return: A `Response` object.
|
180
|
+
"""
|
181
|
+
if not custom_config:
|
182
|
+
custom_config = {}
|
183
|
+
|
184
|
+
async with AsyncStealthySession(
|
185
|
+
wait=wait,
|
186
|
+
max_pages=1,
|
187
|
+
proxy=proxy,
|
188
|
+
geoip=geoip,
|
189
|
+
addons=addons,
|
190
|
+
timeout=timeout,
|
191
|
+
cookies=cookies,
|
192
|
+
headless=headless,
|
193
|
+
humanize=humanize,
|
194
|
+
load_dom=load_dom,
|
195
|
+
disable_ads=disable_ads,
|
196
|
+
allow_webgl=allow_webgl,
|
197
|
+
page_action=page_action,
|
198
|
+
init_script=init_script,
|
199
|
+
network_idle=network_idle,
|
200
|
+
block_images=block_images,
|
201
|
+
block_webrtc=block_webrtc,
|
202
|
+
os_randomize=os_randomize,
|
203
|
+
wait_selector=wait_selector,
|
204
|
+
google_search=google_search,
|
205
|
+
extra_headers=extra_headers,
|
206
|
+
solve_cloudflare=solve_cloudflare,
|
207
|
+
disable_resources=disable_resources,
|
208
|
+
wait_selector_state=wait_selector_state,
|
209
|
+
selector_config={**cls._generate_parser_arguments(), **custom_config},
|
210
|
+
additional_args=additional_args or {},
|
211
|
+
) as engine:
|
212
|
+
return await engine.fetch(url)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
from scrapling.engines.static import (
|
2
|
+
FetcherSession,
|
3
|
+
FetcherClient as _FetcherClient,
|
4
|
+
AsyncFetcherClient as _AsyncFetcherClient,
|
5
|
+
)
|
6
|
+
from scrapling.engines.toolbelt.custom import BaseFetcher
|
7
|
+
|
8
|
+
|
9
|
+
__FetcherClientInstance__ = _FetcherClient()
|
10
|
+
__AsyncFetcherClientInstance__ = _AsyncFetcherClient()
|
11
|
+
|
12
|
+
|
13
|
+
class Fetcher(BaseFetcher):
|
14
|
+
"""A basic `Fetcher` class type that can only do basic GET, POST, PUT, and DELETE HTTP requests based on `curl_cffi`."""
|
15
|
+
|
16
|
+
get = __FetcherClientInstance__.get
|
17
|
+
post = __FetcherClientInstance__.post
|
18
|
+
put = __FetcherClientInstance__.put
|
19
|
+
delete = __FetcherClientInstance__.delete
|
20
|
+
|
21
|
+
|
22
|
+
class AsyncFetcher(BaseFetcher):
|
23
|
+
"""A basic `Fetcher` class type that can only do basic GET, POST, PUT, and DELETE HTTP requests based on `curl_cffi`."""
|
24
|
+
|
25
|
+
get = __AsyncFetcherClientInstance__.get
|
26
|
+
post = __AsyncFetcherClientInstance__.post
|
27
|
+
put = __AsyncFetcherClientInstance__.put
|
28
|
+
delete = __AsyncFetcherClientInstance__.delete
|