osn-selenium 0.0.0__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.
- osn_selenium/__init__.py +1 -0
- osn_selenium/browsers_handler/__init__.py +70 -0
- osn_selenium/browsers_handler/_windows.py +130 -0
- osn_selenium/browsers_handler/types.py +20 -0
- osn_selenium/captcha_workers/__init__.py +26 -0
- osn_selenium/dev_tools/__init__.py +1 -0
- osn_selenium/dev_tools/_types.py +22 -0
- osn_selenium/dev_tools/domains/__init__.py +63 -0
- osn_selenium/dev_tools/domains/abstract.py +378 -0
- osn_selenium/dev_tools/domains/fetch.py +1295 -0
- osn_selenium/dev_tools/domains_default/__init__.py +1 -0
- osn_selenium/dev_tools/domains_default/fetch.py +155 -0
- osn_selenium/dev_tools/errors.py +89 -0
- osn_selenium/dev_tools/logger.py +558 -0
- osn_selenium/dev_tools/manager.py +1551 -0
- osn_selenium/dev_tools/utils.py +509 -0
- osn_selenium/errors.py +16 -0
- osn_selenium/types.py +118 -0
- osn_selenium/webdrivers/BaseDriver/__init__.py +1 -0
- osn_selenium/webdrivers/BaseDriver/_utils.py +37 -0
- osn_selenium/webdrivers/BaseDriver/flags.py +644 -0
- osn_selenium/webdrivers/BaseDriver/protocols.py +2135 -0
- osn_selenium/webdrivers/BaseDriver/trio_wrapper.py +71 -0
- osn_selenium/webdrivers/BaseDriver/webdriver.py +2626 -0
- osn_selenium/webdrivers/Blink/__init__.py +1 -0
- osn_selenium/webdrivers/Blink/flags.py +1349 -0
- osn_selenium/webdrivers/Blink/protocols.py +330 -0
- osn_selenium/webdrivers/Blink/webdriver.py +637 -0
- osn_selenium/webdrivers/Chrome/__init__.py +1 -0
- osn_selenium/webdrivers/Chrome/flags.py +192 -0
- osn_selenium/webdrivers/Chrome/protocols.py +228 -0
- osn_selenium/webdrivers/Chrome/webdriver.py +394 -0
- osn_selenium/webdrivers/Edge/__init__.py +1 -0
- osn_selenium/webdrivers/Edge/flags.py +192 -0
- osn_selenium/webdrivers/Edge/protocols.py +228 -0
- osn_selenium/webdrivers/Edge/webdriver.py +394 -0
- osn_selenium/webdrivers/Yandex/__init__.py +1 -0
- osn_selenium/webdrivers/Yandex/flags.py +192 -0
- osn_selenium/webdrivers/Yandex/protocols.py +211 -0
- osn_selenium/webdrivers/Yandex/webdriver.py +350 -0
- osn_selenium/webdrivers/__init__.py +1 -0
- osn_selenium/webdrivers/_functions.py +504 -0
- osn_selenium/webdrivers/js_scripts/check_element_in_viewport.js +18 -0
- osn_selenium/webdrivers/js_scripts/get_document_scroll_size.js +4 -0
- osn_selenium/webdrivers/js_scripts/get_element_css.js +6 -0
- osn_selenium/webdrivers/js_scripts/get_element_rect_in_viewport.js +9 -0
- osn_selenium/webdrivers/js_scripts/get_random_element_point_in_viewport.js +59 -0
- osn_selenium/webdrivers/js_scripts/get_viewport_position.js +4 -0
- osn_selenium/webdrivers/js_scripts/get_viewport_rect.js +6 -0
- osn_selenium/webdrivers/js_scripts/get_viewport_size.js +4 -0
- osn_selenium/webdrivers/js_scripts/open_new_tab.js +1 -0
- osn_selenium/webdrivers/js_scripts/stop_window_loading.js +1 -0
- osn_selenium/webdrivers/types.py +390 -0
- osn_selenium-0.0.0.dist-info/METADATA +710 -0
- osn_selenium-0.0.0.dist-info/RECORD +57 -0
- osn_selenium-0.0.0.dist-info/WHEEL +5 -0
- osn_selenium-0.0.0.dist-info/top_level.txt +1 -0
osn_selenium/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import pathlib
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from osn_selenium.browsers_handler.types import Browser
|
|
5
|
+
from osn_selenium.errors import (
|
|
6
|
+
PlatformNotSupportedError
|
|
7
|
+
)
|
|
8
|
+
from osn_selenium.browsers_handler._windows import (
|
|
9
|
+
get_installed_browsers_win32
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_installed_browsers() -> list[Browser]:
|
|
14
|
+
"""
|
|
15
|
+
Retrieves a list of installed browsers on the system.
|
|
16
|
+
|
|
17
|
+
This function detects and lists the browsers installed on the operating system.
|
|
18
|
+
It supports different operating systems and uses platform-specific methods to find installed browsers.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
list[Browser]: A list of installed browsers. Each item in the list is a dictionary of type `Browser` containing information about the browser like name, version, and path.
|
|
22
|
+
|
|
23
|
+
Raises:
|
|
24
|
+
PlatformNotSupportedError: If the operating system is not supported.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
if sys.platform == "win32":
|
|
28
|
+
return get_installed_browsers_win32()
|
|
29
|
+
else:
|
|
30
|
+
raise PlatformNotSupportedError(sys.platform)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_version_of_browser(browser_name: str) -> Optional[str]:
|
|
34
|
+
"""
|
|
35
|
+
Retrieves the version of a specific installed browser.
|
|
36
|
+
|
|
37
|
+
This function searches for an installed browser by its name and returns its version if found.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
browser_name (str): The name of the browser to find the version for (e.g., "Chrome", "Firefox").
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
Optional[str]: The version string of the browser if found, otherwise None.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
for browser in get_installed_browsers():
|
|
47
|
+
if browser["name"] == browser_name:
|
|
48
|
+
return browser["version"]
|
|
49
|
+
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def get_path_to_browser(browser_name: str) -> Optional[pathlib.Path]:
|
|
54
|
+
"""
|
|
55
|
+
Retrieves the installation path of a specific installed browser.
|
|
56
|
+
|
|
57
|
+
This function searches for an installed browser by its name and returns its installation path as a pathlib.Path object if found.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
browser_name (str): The name of the browser to find the path for (e.g., "Chrome", "Firefox").
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
Optional[pathlib.Path]: The pathlib.Path object representing the browser's installation path if found, otherwise None.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
for browser in get_installed_browsers():
|
|
67
|
+
if browser["name"] == browser_name:
|
|
68
|
+
return browser["path"]
|
|
69
|
+
|
|
70
|
+
return None
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import winreg
|
|
3
|
+
import pathlib
|
|
4
|
+
import subprocess
|
|
5
|
+
from typing import Optional, Union
|
|
6
|
+
from osn_selenium.browsers_handler.types import Browser
|
|
7
|
+
from win32api import (
|
|
8
|
+
GetFileVersionInfo,
|
|
9
|
+
HIWORD,
|
|
10
|
+
LOWORD
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_webdriver_version(driver_path: Union[pathlib.Path, str]) -> Optional[str]:
|
|
15
|
+
"""
|
|
16
|
+
Retrieves the version of a given webdriver executable.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
driver_path (Union[pathlib.Path, str]): The path to the webdriver executable. It can be a string or a pathlib.Path object.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
Optional[str]: The version of the webdriver as a string, or None if the version cannot be determined.
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
FileNotFoundError: If the webdriver executable does not exist at the given path.
|
|
26
|
+
Exception: If there is an error executing the webdriver or parsing the output.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
if isinstance(driver_path, str):
|
|
30
|
+
driver_path = pathlib.Path(driver_path)
|
|
31
|
+
|
|
32
|
+
if not driver_path.exists():
|
|
33
|
+
raise FileNotFoundError(f"{driver_path} not found.")
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
process = subprocess.Popen(
|
|
37
|
+
[driver_path, "--version"],
|
|
38
|
+
stdout=subprocess.PIPE,
|
|
39
|
+
stderr=subprocess.PIPE
|
|
40
|
+
)
|
|
41
|
+
stdout, stderr = process.communicate()
|
|
42
|
+
|
|
43
|
+
output = stdout.decode("utf-8").strip()
|
|
44
|
+
error = stderr.decode("utf-8").strip()
|
|
45
|
+
|
|
46
|
+
if error:
|
|
47
|
+
raise Exception(error)
|
|
48
|
+
|
|
49
|
+
match = re.search(r"([\d.]+)", output)
|
|
50
|
+
if match:
|
|
51
|
+
return match.group(1)
|
|
52
|
+
|
|
53
|
+
return None
|
|
54
|
+
except Exception as e:
|
|
55
|
+
raise e
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_browser_version(browser_path: Union[pathlib.Path, str]) -> str:
|
|
59
|
+
"""
|
|
60
|
+
Retrieves the version of a browser given its file path.
|
|
61
|
+
|
|
62
|
+
This function uses the `GetFileVersionInfo` function from the `win32api` module to extract the browser's version information from the executable file.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
browser_path (pathlib.Path): The file path to the browser executable.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
str: The version of the browser as a string, or "unknown" if the file does not exist.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
if isinstance(browser_path, str):
|
|
72
|
+
browser_path = pathlib.Path(browser_path)
|
|
73
|
+
|
|
74
|
+
if not browser_path.exists():
|
|
75
|
+
return "unknown"
|
|
76
|
+
|
|
77
|
+
info = GetFileVersionInfo(str(browser_path.resolve()), "\\")
|
|
78
|
+
ms = info["FileVersionMS"]
|
|
79
|
+
ls = info["FileVersionLS"]
|
|
80
|
+
|
|
81
|
+
return ".".join(map(str, (HIWORD(ms), LOWORD(ms), HIWORD(ls), LOWORD(ls))))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def get_installed_browsers_win32() -> list[Browser]:
|
|
85
|
+
"""
|
|
86
|
+
Retrieves a list of installed browsers on a Windows system by querying the registry.
|
|
87
|
+
|
|
88
|
+
This function iterates through different registry locations to identify installed browsers and their paths.
|
|
89
|
+
It constructs a list of unique `Browser` objects, each representing an installed browser.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
list[Browser]: A list of unique installed browsers.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
installed_browsers = []
|
|
96
|
+
|
|
97
|
+
for root_key, access in [
|
|
98
|
+
(winreg.HKEY_CURRENT_USER, winreg.KEY_READ),
|
|
99
|
+
(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_READ | winreg.KEY_WOW64_64KEY),
|
|
100
|
+
(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
|
|
101
|
+
]:
|
|
102
|
+
with winreg.OpenKey(root_key, r"SOFTWARE\Clients\StartMenuInternet", access=access) as key:
|
|
103
|
+
num_subkeys = winreg.QueryInfoKey(key)[0]
|
|
104
|
+
|
|
105
|
+
for i in range(num_subkeys):
|
|
106
|
+
try:
|
|
107
|
+
subkey = winreg.EnumKey(key, i)
|
|
108
|
+
|
|
109
|
+
browser_name = winreg.QueryValue(key, subkey)
|
|
110
|
+
if not browser_name or not isinstance(browser_name, str):
|
|
111
|
+
browser_name = subkey
|
|
112
|
+
|
|
113
|
+
with winreg.OpenKey(key, rf"{subkey}\shell\open\command") as subkey:
|
|
114
|
+
browser_path = pathlib.Path(winreg.QueryValue(subkey, None).strip('"'))
|
|
115
|
+
|
|
116
|
+
if not browser_path.exists():
|
|
117
|
+
continue
|
|
118
|
+
|
|
119
|
+
found_browser = Browser(
|
|
120
|
+
name=browser_name,
|
|
121
|
+
path=browser_path,
|
|
122
|
+
version=get_browser_version(browser_path)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
if found_browser not in installed_browsers:
|
|
126
|
+
installed_browsers.append(found_browser)
|
|
127
|
+
except (OSError, AttributeError, TypeError, ValueError, FileNotFoundError):
|
|
128
|
+
pass
|
|
129
|
+
|
|
130
|
+
return installed_browsers
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
from typing import TypedDict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Browser(TypedDict):
|
|
6
|
+
"""
|
|
7
|
+
Represents a browser installed on the system.
|
|
8
|
+
|
|
9
|
+
This class is a TypedDict, which provides a way to define the structure of a dictionary with specific keys and value types.
|
|
10
|
+
It is used to store information about a browser, such as its name, installation path, and version.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
name (str): The name of the browser (e.g., "Chrome", "Firefox").
|
|
14
|
+
path (pathlib.Path): The file path to the browser executable.
|
|
15
|
+
version (str): The version number of the browser.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
name: str
|
|
19
|
+
path: pathlib.Path
|
|
20
|
+
version: str
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from typing import (
|
|
2
|
+
Callable,
|
|
3
|
+
TYPE_CHECKING,
|
|
4
|
+
TypedDict
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from osn_selenium.webdrivers.BaseDriver.webdriver import BrowserWebDriver
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CaptchaWorkerSettings(TypedDict):
|
|
13
|
+
"""
|
|
14
|
+
Typed dictionary for defining a captcha worker.
|
|
15
|
+
|
|
16
|
+
Attributes:
|
|
17
|
+
name (str): A unique name for the captcha worker.
|
|
18
|
+
check_func (Callable[["BrowserWebDriver"], bool]): A callable function that takes a
|
|
19
|
+
`BrowserWebDriver` instance and returns `True` if a captcha is detected.
|
|
20
|
+
solve_func (Callable[["BrowserWebDriver"], None]): A callable function that takes a
|
|
21
|
+
`BrowserWebDriver` instance and attempts to solve the captcha.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
name: str
|
|
25
|
+
check_func: Callable[["BrowserWebDriver"], bool]
|
|
26
|
+
solve_func: Callable[["BrowserWebDriver"], None]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from typing import (
|
|
2
|
+
Awaitable,
|
|
3
|
+
Callable,
|
|
4
|
+
Literal,
|
|
5
|
+
TYPE_CHECKING
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from osn_selenium.dev_tools.manager import DevToolsTarget
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
devtools_background_func_type = Callable[["DevToolsTarget"], Awaitable[None]]
|
|
14
|
+
LogLevelsType = Literal[
|
|
15
|
+
"INFO",
|
|
16
|
+
"ERROR",
|
|
17
|
+
"DEBUG",
|
|
18
|
+
"WARNING",
|
|
19
|
+
"RequestPaused",
|
|
20
|
+
"AuthRequired",
|
|
21
|
+
"Building Kwargs"
|
|
22
|
+
]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import (
|
|
3
|
+
Literal,
|
|
4
|
+
Optional,
|
|
5
|
+
TypedDict,
|
|
6
|
+
Union
|
|
7
|
+
)
|
|
8
|
+
from osn_selenium.dev_tools.domains.fetch import (
|
|
9
|
+
FetchSettings,
|
|
10
|
+
_Fetch
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Domains(TypedDict, total=False):
|
|
15
|
+
"""
|
|
16
|
+
Settings for configuring callbacks for different DevTools event domains.
|
|
17
|
+
|
|
18
|
+
This TypedDict aggregates settings for various DevTools event types, allowing for structured configuration
|
|
19
|
+
of event handling within the DevTools integration. Currently, it specifically includes settings for the 'fetch' domain.
|
|
20
|
+
|
|
21
|
+
Attributes:
|
|
22
|
+
fetch (_Fetch): Configuration settings for the Fetch domain events.
|
|
23
|
+
This includes settings to enable/disable fetch event handling and specific configurations for 'requestPaused' events.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
fetch: _Fetch
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class DomainsSettings:
|
|
31
|
+
"""
|
|
32
|
+
A dataclass container for configuration settings across different DevTools domains.
|
|
33
|
+
|
|
34
|
+
This class provides a structured way to define the desired behavior for various
|
|
35
|
+
CDP domains like Fetch, Network, etc., when the DevTools context is active.
|
|
36
|
+
|
|
37
|
+
Attributes:
|
|
38
|
+
fetch (Optional[FetchSettings]): Configuration settings for the Fetch domain. If None, the Fetch domain will not be enabled or handled. Defaults to None.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
fetch: Optional[FetchSettings] = None
|
|
42
|
+
|
|
43
|
+
def to_dict(self) -> Domains:
|
|
44
|
+
"""
|
|
45
|
+
Converts the dataclass instance to its dictionary representation.
|
|
46
|
+
|
|
47
|
+
This method is used internally to transform the structured settings from the
|
|
48
|
+
dataclass into the `Domains` TypedDict format expected by the DevTools manager.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Domains: A dictionary containing the settings for each configured domain.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
kwargs = {}
|
|
55
|
+
|
|
56
|
+
if self.fetch is not None:
|
|
57
|
+
kwargs["fetch"] = self.fetch.to_dict()
|
|
58
|
+
|
|
59
|
+
return Domains(**kwargs)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
domains_type = Literal["fetch"]
|
|
63
|
+
domains_classes_type = Union[_Fetch]
|