StealthyFetcher - The option to drop unnecessary resources requests for speed boost
This commit is contained in:
@@ -5,6 +5,7 @@ from scrapling.engines.toolbelt import (
|
|||||||
Response,
|
Response,
|
||||||
do_nothing,
|
do_nothing,
|
||||||
get_os_name,
|
get_os_name,
|
||||||
|
intercept_route,
|
||||||
check_type_validity,
|
check_type_validity,
|
||||||
generate_convincing_referer,
|
generate_convincing_referer,
|
||||||
)
|
)
|
||||||
@@ -16,6 +17,7 @@ class CamoufoxEngine:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self, headless: Union[bool, str] = True,
|
self, headless: Union[bool, str] = True,
|
||||||
block_images: Optional[bool] = False,
|
block_images: Optional[bool] = False,
|
||||||
|
disable_resources: Optional[bool] = False,
|
||||||
block_webrtc: Optional[bool] = False,
|
block_webrtc: Optional[bool] = False,
|
||||||
allow_webgl: Optional[bool] = False,
|
allow_webgl: Optional[bool] = False,
|
||||||
network_idle: Optional[bool] = False,
|
network_idle: Optional[bool] = False,
|
||||||
@@ -27,6 +29,7 @@ class CamoufoxEngine:
|
|||||||
):
|
):
|
||||||
self.headless = headless
|
self.headless = headless
|
||||||
self.block_images = bool(block_images)
|
self.block_images = bool(block_images)
|
||||||
|
self.disable_resources = bool(disable_resources)
|
||||||
self.block_webrtc = bool(block_webrtc)
|
self.block_webrtc = bool(block_webrtc)
|
||||||
self.allow_webgl = bool(allow_webgl)
|
self.allow_webgl = bool(allow_webgl)
|
||||||
self.network_idle = bool(network_idle)
|
self.network_idle = bool(network_idle)
|
||||||
@@ -52,6 +55,9 @@ class CamoufoxEngine:
|
|||||||
page = browser.new_page()
|
page = browser.new_page()
|
||||||
page.set_default_navigation_timeout(self.timeout)
|
page.set_default_navigation_timeout(self.timeout)
|
||||||
page.set_default_timeout(self.timeout)
|
page.set_default_timeout(self.timeout)
|
||||||
|
if self.disable_resources:
|
||||||
|
page.route("**/*", intercept_route)
|
||||||
|
|
||||||
res = page.goto(url, referer=generate_convincing_referer(url))
|
res = page.goto(url, referer=generate_convincing_referer(url))
|
||||||
page.wait_for_load_state(state="load")
|
page.wait_for_load_state(state="load")
|
||||||
page.wait_for_load_state(state="domcontentloaded")
|
page.wait_for_load_state(state="domcontentloaded")
|
||||||
|
|||||||
Reference in New Issue
Block a user