util
T = typing.TypeVar('T')
module-attribute
__registered__instances__: Set[Browser] = set()
module-attribute
logger = logging.getLogger(__name__)
module-attribute
cdp_get_module(domain)
get cdp module by given string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
Union[str, ModuleType]
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in zendriver/core/util.py
circle(x, y=None, radius=10, num=10, dir=0)
a generator will calculate coordinates around a circle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
start x position |
required |
y
|
float | None
|
start y position |
None
|
radius
|
int
|
size of the circle |
10
|
num
|
int
|
the amount of points calculated (higher => slower, more cpu, but more detailed) |
10
|
Returns:
| Type | Description |
|---|---|
|
|
Source code in zendriver/core/util.py
compare_target_info(info1, info2)
when logging mode is set to debug, browser object will log when target info is changed. To provide more meaningful log messages, this function is called to check what has actually changed between the 2 (by simple dict comparison). it returns a list of tuples [ ... ( key_which_has_changed, old_value, new_value) ]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info1
|
TargetInfo | None
|
|
required |
info2
|
TargetInfo
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in zendriver/core/util.py
create_from_undetected_chromedriver(driver)
async
create a zendriver.Browser instance from a running undetected_chromedriver.Chrome instance.
Source code in zendriver/core/util.py
filter_recurse(doc, predicate)
test each child using predicate(child), and return the first child of which predicate(child) == True
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Node
|
the cdp.dom.Node object or :py:class: |
required |
predicate
|
Callable[[Node], bool]
|
a function which takes a node as first parameter and returns a boolean, where True means include |
required |
Source code in zendriver/core/util.py
filter_recurse_all(doc, predicate)
test each child using predicate(child), and return all children for which predicate(child) == True
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
T
|
the cdp.dom.Node object or :py:class: |
required |
predicate
|
Union[Callable[[Node], bool], Callable[[Element], bool]]
|
a function which takes a node as first parameter and returns a boolean, where True means include |
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in zendriver/core/util.py
free_port()
Determines a free port using sockets.
Source code in zendriver/core/util.py
get_registered_instances()
html_from_tree(tree, target)
async
Source code in zendriver/core/util.py
loop()
remove_from_tree(tree, node)
Source code in zendriver/core/util.py
start(config=None, *, user_data_dir=None, headless=False, browser_executable_path=None, browser='auto', browser_args=None, sandbox=True, lang=None, host=None, port=None, expert=None, user_agent=None, **kwargs)
async
helper function to launch a browser. it accepts several keyword parameters.
conveniently, you can just call it bare (no parameters) to quickly launch an instance
with best practice defaults.
note: this should be called await start()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_data_dir
|
Optional[PathLike]
|
|
None
|
headless
|
Optional[bool]
|
|
False
|
browser_executable_path
|
Optional[PathLike]
|
|
None
|
browser_args
|
Optional[List[str]]
|
["--some-chromeparam=somevalue", "some-other-param=someval"] |
None
|
sandbox
|
Optional[bool]
|
default True, but when set to False it adds --no-sandbox to the params, also when using linux under a root user, it adds False automatically (else chrome won't start |
True
|
lang
|
Optional[str]
|
language string |
None
|
port
|
Optional[int]
|
if you connect to an existing debuggable session, you can specify the port here if both host and port are provided, zendriver will not start a local chrome browser! |
None
|
host
|
Optional[str]
|
if you connect to an existing debuggable session, you can specify the host here if both host and port are provided, zendriver will not start a local chrome browser! |
None
|
expert
|
Optional[bool]
|
when set to True, enabled "expert" mode. This conveys, the inclusion of parameters: --disable-web-security ----disable-site-isolation-trials, as well as some scripts and patching useful for debugging (for example, ensuring shadow-root is always in "open" mode) |
None
|
user_agent
|
Optional[str]
|
if set, this will be used as the user agent for the browser. |
None
|
Returns:
| Type | Description |
|---|---|
Browser
|
|