feat(DynamicSession): Improve normal fetches speed
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from .constants import DEFAULT_DISABLED_RESOURCES, DEFAULT_STEALTH_FLAGS
|
from .constants import DEFAULT_DISABLED_RESOURCES, DEFAULT_STEALTH_FLAGS, DEFAULT_FLAGS
|
||||||
from .static import FetcherSession, FetcherClient, AsyncFetcherClient
|
from .static import FetcherSession, FetcherClient, AsyncFetcherClient
|
||||||
from ._browsers import (
|
from ._browsers import (
|
||||||
DynamicSession,
|
DynamicSession,
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
|
||||||
from scrapling.core._types import Tuple
|
from scrapling.core._types import Tuple
|
||||||
from scrapling.engines.constants import DEFAULT_STEALTH_FLAGS, HARMFUL_DEFAULT_ARGS
|
from scrapling.engines.constants import (
|
||||||
|
DEFAULT_STEALTH_FLAGS,
|
||||||
|
HARMFUL_DEFAULT_ARGS,
|
||||||
|
DEFAULT_FLAGS,
|
||||||
|
)
|
||||||
from scrapling.engines.toolbelt import js_bypass_path, generate_headers
|
from scrapling.engines.toolbelt import js_bypass_path, generate_headers
|
||||||
|
|
||||||
__default_useragent__ = generate_headers(browser_mode=True).get("User-Agent")
|
__default_useragent__ = generate_headers(browser_mode=True).get("User-Agent")
|
||||||
@@ -69,20 +73,21 @@ def _launch_kwargs(
|
|||||||
) -> Tuple:
|
) -> Tuple:
|
||||||
"""Creates the arguments we will use while launching playwright's browser"""
|
"""Creates the arguments we will use while launching playwright's browser"""
|
||||||
launch_kwargs = {
|
launch_kwargs = {
|
||||||
|
"locale": locale,
|
||||||
"headless": headless,
|
"headless": headless,
|
||||||
|
"args": DEFAULT_FLAGS,
|
||||||
|
"color_scheme": "dark", # Bypasses the 'prefersLightColor' check in creepjs
|
||||||
|
"proxy": proxy or tuple(),
|
||||||
|
"device_scale_factor": 2,
|
||||||
"ignore_default_args": HARMFUL_DEFAULT_ARGS,
|
"ignore_default_args": HARMFUL_DEFAULT_ARGS,
|
||||||
"channel": "chrome" if real_chrome else "chromium",
|
"channel": "chrome" if real_chrome else "chromium",
|
||||||
"proxy": proxy or tuple(),
|
|
||||||
"locale": locale,
|
|
||||||
"color_scheme": "dark", # Bypasses the 'prefersLightColor' check in creepjs
|
|
||||||
"device_scale_factor": 2,
|
|
||||||
"extra_http_headers": extra_headers or tuple(),
|
"extra_http_headers": extra_headers or tuple(),
|
||||||
"user_agent": useragent or __default_useragent__,
|
"user_agent": useragent or __default_useragent__,
|
||||||
}
|
}
|
||||||
if stealth:
|
if stealth:
|
||||||
launch_kwargs.update(
|
launch_kwargs.update(
|
||||||
{
|
{
|
||||||
"args": _set_flags(hide_canvas, disable_webgl),
|
"args": DEFAULT_FLAGS + _set_flags(hide_canvas, disable_webgl),
|
||||||
"chromium_sandbox": True,
|
"chromium_sandbox": True,
|
||||||
"is_mobile": False,
|
"is_mobile": False,
|
||||||
"has_touch": False,
|
"has_touch": False,
|
||||||
|
|||||||
@@ -21,22 +21,32 @@ HARMFUL_DEFAULT_ARGS = (
|
|||||||
# '--disable-extensions',
|
# '--disable-extensions',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
DEFAULT_FLAGS = (
|
||||||
|
# Speed up chromium browsers by default
|
||||||
|
"--no-pings",
|
||||||
|
"--no-first-run",
|
||||||
|
"--disable-infobars",
|
||||||
|
"--disable-breakpad",
|
||||||
|
"--no-service-autorun",
|
||||||
|
"--homepage=about:blank",
|
||||||
|
"--password-store=basic",
|
||||||
|
"--no-default-browser-check",
|
||||||
|
"--disable-session-crashed-bubble",
|
||||||
|
"--disable-search-engine-choice-screen",
|
||||||
|
)
|
||||||
|
|
||||||
DEFAULT_STEALTH_FLAGS = (
|
DEFAULT_STEALTH_FLAGS = (
|
||||||
# Explanation: https://peter.sh/experiments/chromium-command-line-switches/
|
# Explanation: https://peter.sh/experiments/chromium-command-line-switches/
|
||||||
# Generally this will make the browser faster and less detectable
|
# Generally this will make the browser faster and less detectable
|
||||||
"--no-pings",
|
|
||||||
"--incognito",
|
"--incognito",
|
||||||
"--test-type",
|
"--test-type",
|
||||||
"--lang=en-US",
|
"--lang=en-US",
|
||||||
"--mute-audio",
|
"--mute-audio",
|
||||||
"--no-first-run",
|
|
||||||
"--disable-sync",
|
"--disable-sync",
|
||||||
"--hide-scrollbars",
|
"--hide-scrollbars",
|
||||||
"--disable-logging",
|
"--disable-logging",
|
||||||
"--start-maximized", # For headless check bypass
|
"--start-maximized", # For headless check bypass
|
||||||
"--enable-async-dns",
|
"--enable-async-dns",
|
||||||
"--disable-breakpad",
|
|
||||||
"--disable-infobars",
|
|
||||||
"--accept-lang=en-US",
|
"--accept-lang=en-US",
|
||||||
"--use-mock-keychain",
|
"--use-mock-keychain",
|
||||||
"--disable-translate",
|
"--disable-translate",
|
||||||
@@ -48,7 +58,6 @@ DEFAULT_STEALTH_FLAGS = (
|
|||||||
"--enable-tcp-fast-open",
|
"--enable-tcp-fast-open",
|
||||||
"--enable-web-bluetooth",
|
"--enable-web-bluetooth",
|
||||||
"--disable-hang-monitor",
|
"--disable-hang-monitor",
|
||||||
"--password-store=basic",
|
|
||||||
"--disable-cloud-import",
|
"--disable-cloud-import",
|
||||||
"--disable-default-apps",
|
"--disable-default-apps",
|
||||||
"--disable-print-preview",
|
"--disable-print-preview",
|
||||||
@@ -62,17 +71,15 @@ DEFAULT_STEALTH_FLAGS = (
|
|||||||
"--disable-prompt-on-repost",
|
"--disable-prompt-on-repost",
|
||||||
"--force-color-profile=srgb",
|
"--force-color-profile=srgb",
|
||||||
"--font-render-hinting=none",
|
"--font-render-hinting=none",
|
||||||
"--no-default-browser-check",
|
|
||||||
"--aggressive-cache-discard",
|
"--aggressive-cache-discard",
|
||||||
"--disable-component-update",
|
"--disable-component-update",
|
||||||
"--disable-cookie-encryption",
|
"--disable-cookie-encryption",
|
||||||
"--disable-domain-reliability",
|
"--disable-domain-reliability",
|
||||||
"--disable-threaded-animation",
|
"--disable-threaded-animation",
|
||||||
"--disable-threaded-scrolling",
|
"--disable-threaded-scrolling",
|
||||||
# '--disable-reading-from-canvas', # For Firefox
|
# '--disable-reading-from-canvas', # For Firefox
|
||||||
"--enable-simple-cache-backend",
|
"--enable-simple-cache-backend",
|
||||||
"--disable-background-networking",
|
"--disable-background-networking",
|
||||||
"--disable-session-crashed-bubble",
|
|
||||||
"--enable-surface-synchronization",
|
"--enable-surface-synchronization",
|
||||||
"--disable-image-animation-resync",
|
"--disable-image-animation-resync",
|
||||||
"--disable-renderer-backgrounding",
|
"--disable-renderer-backgrounding",
|
||||||
|
|||||||
Reference in New Issue
Block a user