mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
WebPage删除check_page();调整SessionElement相对定位参数顺序;优化存根文件
This commit is contained in:
parent
1994261b00
commit
c72f4ba8d9
@ -5,7 +5,7 @@
|
|||||||
"""
|
"""
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from .common import _location_in_viewport
|
from .common import location_in_viewport
|
||||||
from .keys import _modifierBit, _keyDescriptionForString
|
from .keys import _modifierBit, _keyDescriptionForString
|
||||||
|
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ class ActionChains:
|
|||||||
else:
|
else:
|
||||||
raise TypeError('ele_or_loc参数只能接受坐标(x, y)或ChromiumElement对象。')
|
raise TypeError('ele_or_loc参数只能接受坐标(x, y)或ChromiumElement对象。')
|
||||||
|
|
||||||
if not _location_in_viewport(self.page, lx, ly):
|
if not location_in_viewport(self.page, lx, ly):
|
||||||
# 把元素滚动到页面中间
|
# 把元素滚动到页面中间
|
||||||
clientWidth = self.page.run_js('return document.body.clientWidth;')
|
clientWidth = self.page.run_js('return document.body.clientWidth;')
|
||||||
clientHeight = self.page.run_js('return document.body.clientHeight;')
|
clientHeight = self.page.run_js('return document.body.clientHeight;')
|
||||||
|
@ -16,38 +16,39 @@ class ActionChains:
|
|||||||
def __init__(self, page: ChromiumBase):
|
def __init__(self, page: ChromiumBase):
|
||||||
self.page: ChromiumPage = ...
|
self.page: ChromiumPage = ...
|
||||||
self._dr: ChromiumDriver = ...
|
self._dr: ChromiumDriver = ...
|
||||||
|
self.modifier: int = ...
|
||||||
self.curr_x: int = ...
|
self.curr_x: int = ...
|
||||||
self.curr_y: int = ...
|
self.curr_y: int = ...
|
||||||
self.modifier: int = ...
|
|
||||||
|
|
||||||
def move_to(self, ele_or_loc: Union[ChromiumElement, Tuple[int, int], str],
|
def move_to(self, ele_or_loc: Union[ChromiumElement, Tuple[int, int], str],
|
||||||
offset_x: int = ..., offset_y: int = ...) -> ActionChains: ...
|
offset_x: int = 0, offset_y: int = 0) -> ActionChains: ...
|
||||||
|
|
||||||
def move(self, offset_x: int = ..., offset_y: int = ...) -> ActionChains: ...
|
def move(self, offset_x: int = 0, offset_y: int = 0) -> ActionChains: ...
|
||||||
|
|
||||||
def click(self, on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def click(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def r_click(self, on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def r_click(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def m_click(self, on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def m_click(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def hold(self, on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def hold(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def release(self, on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def release(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def r_hold(self, on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def r_hold(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def r_release(self, on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def r_release(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def m_hold(self, on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def m_hold(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def m_release(self, on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def m_release(self, on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def _hold(self, button: str) -> ActionChains: ...
|
def _hold(self, button: str) -> ActionChains: ...
|
||||||
|
|
||||||
def _release(self, button: str) -> ActionChains: ...
|
def _release(self, button: str) -> ActionChains: ...
|
||||||
|
|
||||||
def scroll(self, delta_x: int = ..., delta_y: int = ..., on_ele: Union[ChromiumElement, str] = ...) -> ActionChains: ...
|
def scroll(self, delta_x: int = 0, delta_y: int = 0,
|
||||||
|
on_ele: Union[ChromiumElement, str] = None) -> ActionChains: ...
|
||||||
|
|
||||||
def up(self, pixel: int) -> ActionChains: ...
|
def up(self, pixel: int) -> ActionChains: ...
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ class DrissionElement(BaseElement):
|
|||||||
"""
|
"""
|
||||||
return self._get_brothers(filter_loc=filter_loc, direction='preceding', brother=False, timeout=timeout)
|
return self._get_brothers(filter_loc=filter_loc, direction='preceding', brother=False, timeout=timeout)
|
||||||
|
|
||||||
def afters(self, filter_loc, timeout=None):
|
def afters(self, filter_loc='', timeout=None):
|
||||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选 \n
|
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选 \n
|
||||||
:param filter_loc: 用于筛选元素的查询语法
|
:param filter_loc: 用于筛选元素的查询语法
|
||||||
:param timeout: 查找元素的超时时间
|
:param timeout: 查找元素的超时时间
|
||||||
|
@ -11,9 +11,9 @@ class BaseParser(object):
|
|||||||
|
|
||||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str]): ...
|
def __call__(self, loc_or_str: Union[Tuple[str, str], str]): ...
|
||||||
|
|
||||||
def ele(self, loc_or_ele: Union[Tuple[str, str], str, BaseElement], timeout:float=...): ...
|
def ele(self, loc_or_ele: Union[Tuple[str, str], str, BaseElement], timeout: float = None): ...
|
||||||
|
|
||||||
def eles(self, loc_or_str: Union[Tuple[str, str], str], timeout=...): ...
|
def eles(self, loc_or_str: Union[Tuple[str, str], str], timeout=None): ...
|
||||||
|
|
||||||
# ----------------以下属性或方法待后代实现----------------
|
# ----------------以下属性或方法待后代实现----------------
|
||||||
@property
|
@property
|
||||||
@ -24,28 +24,29 @@ class BaseParser(object):
|
|||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]): ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]): ...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _ele(self, loc_or_ele, timeout:float=..., single:bool=...): ...
|
def _ele(self, loc_or_ele, timeout: float = None, single: bool = True): ...
|
||||||
|
|
||||||
|
|
||||||
class BaseElement(BaseParser):
|
class BaseElement(BaseParser):
|
||||||
|
|
||||||
def __init__(self, page: BasePage):
|
def __init__(self, page: BasePage = None):
|
||||||
self.page: BasePage = ...
|
self.page: BasePage = ...
|
||||||
|
|
||||||
# ----------------以下属性或方法由后代实现----------------
|
# ----------------以下属性或方法由后代实现----------------
|
||||||
@property
|
@property
|
||||||
def tag(self)->str: ...
|
def tag(self) -> str: ...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _ele(self, loc_or_str: Union[Tuple[str, str], str], timeout:float=..., single:bool=..., relative:bool=...): ...
|
def _ele(self, loc_or_str: Union[Tuple[str, str], str], timeout: float = None, single: bool = True,
|
||||||
|
relative: bool = False): ...
|
||||||
|
|
||||||
def parent(self, level_or_loc: Union[tuple, str, int] = ...): ...
|
def parent(self, level_or_loc: Union[tuple, str, int] = 1): ...
|
||||||
|
|
||||||
def prev(self, index: int = ...) -> None: ...
|
def prev(self, index: int = 1) -> None: ...
|
||||||
|
|
||||||
def prevs(self) -> None: ...
|
def prevs(self) -> None: ...
|
||||||
|
|
||||||
def next(self, index: int = ...): ...
|
def next(self, index: int = 1): ...
|
||||||
|
|
||||||
def nexts(self): ...
|
def nexts(self): ...
|
||||||
|
|
||||||
@ -68,52 +69,52 @@ class DrissionElement(BaseElement):
|
|||||||
@property
|
@property
|
||||||
def comments(self) -> list: ...
|
def comments(self) -> list: ...
|
||||||
|
|
||||||
def texts(self, text_node_only: bool = ...) -> list: ...
|
def texts(self, text_node_only: bool = False) -> list: ...
|
||||||
|
|
||||||
def parent(self, level_or_loc: Union[tuple, str, int] = ...) -> Union['DrissionElement', None]: ...
|
def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union['DrissionElement', None]: ...
|
||||||
|
|
||||||
def prev(self,
|
def prev(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> Union['DrissionElement', str, None]: ...
|
timeout: float = 0) -> Union['DrissionElement', str, None]: ...
|
||||||
|
|
||||||
def next(self,
|
def next(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> Union['DrissionElement', str, None]: ...
|
timeout: float = 0) -> Union['DrissionElement', str, None]: ...
|
||||||
|
|
||||||
def before(self,
|
def before(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> Union['DrissionElement', str, None]: ...
|
timeout: float = None) -> Union['DrissionElement', str, None]: ...
|
||||||
|
|
||||||
def after(self,
|
def after(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> Union['DrissionElement', str, None]: ...
|
timeout: float = None) -> Union['DrissionElement', str, None]: ...
|
||||||
|
|
||||||
def prevs(self,
|
def prevs(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['DrissionElement', str]]: ...
|
timeout: float = 0) -> List[Union['DrissionElement', str]]: ...
|
||||||
|
|
||||||
def nexts(self,
|
def nexts(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['DrissionElement', str]]: ...
|
timeout: float = 0) -> List[Union['DrissionElement', str]]: ...
|
||||||
|
|
||||||
def befores(self,
|
def befores(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['DrissionElement', str]]: ...
|
timeout: float = None) -> List[Union['DrissionElement', str]]: ...
|
||||||
|
|
||||||
def afters(self,
|
def afters(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['DrissionElement', str]]: ...
|
timeout: float = None) -> List[Union['DrissionElement', str]]: ...
|
||||||
|
|
||||||
def _get_brothers(self,
|
def _get_brothers(self,
|
||||||
index: int = ...,
|
index: int = None,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
direction: str = ...,
|
direction: str = 'following',
|
||||||
brother: bool = ...,
|
brother: bool = True,
|
||||||
timeout: float = ...) -> List[Union['DrissionElement', str]]: ...
|
timeout: float = 0.5) -> List[Union['DrissionElement', str]]: ...
|
||||||
|
|
||||||
# ----------------以下属性或方法由后代实现----------------
|
# ----------------以下属性或方法由后代实现----------------
|
||||||
@property
|
@property
|
||||||
@ -133,7 +134,7 @@ class DrissionElement(BaseElement):
|
|||||||
|
|
||||||
class BasePage(BaseParser):
|
class BasePage(BaseParser):
|
||||||
|
|
||||||
def __init__(self, timeout: float = ...):
|
def __init__(self, timeout: float = None):
|
||||||
self._url_available: bool = ...
|
self._url_available: bool = ...
|
||||||
self.retry_times: int = ...
|
self.retry_times: int = ...
|
||||||
self.retry_interval: float = ...
|
self.retry_interval: float = ...
|
||||||
@ -164,11 +165,11 @@ class BasePage(BaseParser):
|
|||||||
def json(self) -> dict: ...
|
def json(self) -> dict: ...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_cookies(self, as_dict: bool = ...) -> Union[list, dict]: ...
|
def get_cookies(self, as_dict: bool = False) -> Union[list, dict]: ...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get(self,
|
def get(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool = ...,
|
show_errmsg: bool = False,
|
||||||
retry: int = ...,
|
retry: int = None,
|
||||||
interval: float = ...): ...
|
interval: float = None): ...
|
||||||
|
@ -395,7 +395,7 @@ class ChromiumBase(BasePage):
|
|||||||
"""
|
"""
|
||||||
return make_session_ele(self, loc_or_ele)
|
return make_session_ele(self, loc_or_ele)
|
||||||
|
|
||||||
def s_eles(self, loc_or_str=None):
|
def s_eles(self, loc_or_str):
|
||||||
"""查找所有符合条件的元素以SessionElement列表形式返回 \n
|
"""查找所有符合条件的元素以SessionElement列表形式返回 \n
|
||||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:return: SessionElement对象组成的列表
|
:return: SessionElement对象组成的列表
|
||||||
@ -572,7 +572,8 @@ class ChromiumBase(BasePage):
|
|||||||
:param value: 项的值,设置为False时,删除该项
|
:param value: 项的值,设置为False时,删除该项
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
js = f'sessionStorage.removeItem("{item}");' if item is False else f'sessionStorage.setItem("{item}","{value}");'
|
js = f'sessionStorage.removeItem("{item}");' if item is False \
|
||||||
|
else f'sessionStorage.setItem("{item}","{value}");'
|
||||||
return self.run_js(js, as_expr=True)
|
return self.run_js(js, as_expr=True)
|
||||||
|
|
||||||
def set_local_storage(self, item, value):
|
def set_local_storage(self, item, value):
|
||||||
|
@ -21,8 +21,8 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
address: str,
|
address: str,
|
||||||
tab_id: str = ...,
|
tab_id: str = None,
|
||||||
timeout: float = ...):
|
timeout: float = None):
|
||||||
self._control_session: Session = ...
|
self._control_session: Session = ...
|
||||||
self.address: str = ...
|
self.address: str = ...
|
||||||
self._tab_obj: ChromiumDriver = ...
|
self._tab_obj: ChromiumDriver = ...
|
||||||
@ -38,14 +38,14 @@ class ChromiumBase(BasePage):
|
|||||||
self._debug_recorder: Recorder = ...
|
self._debug_recorder: Recorder = ...
|
||||||
|
|
||||||
def _connect_browser(self,
|
def _connect_browser(self,
|
||||||
addr_driver_opts: Union[str, ChromiumDriver, DriverOptions] = ...,
|
addr_driver_opts: Union[str, ChromiumDriver, DriverOptions] = None,
|
||||||
tab_id: str = ...) -> None: ...
|
tab_id: str = None) -> None: ...
|
||||||
|
|
||||||
def _init_page(self, tab_id: str = ...) -> None: ...
|
def _init_page(self, tab_id: str = None) -> None: ...
|
||||||
|
|
||||||
def _get_document(self) -> None: ...
|
def _get_document(self) -> None: ...
|
||||||
|
|
||||||
def _wait_loaded(self, timeout: float = ...) -> bool: ...
|
def _wait_loaded(self, timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def _onFrameStartedLoading(self, **kwargs): ...
|
def _onFrameStartedLoading(self, **kwargs): ...
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ class ChromiumBase(BasePage):
|
|||||||
def _set_options(self) -> None: ...
|
def _set_options(self) -> None: ...
|
||||||
|
|
||||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str, ChromiumElement],
|
def __call__(self, loc_or_str: Union[Tuple[str, str], str, ChromiumElement],
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, None]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self) -> str: ...
|
def title(self) -> str: ...
|
||||||
@ -107,22 +107,22 @@ class ChromiumBase(BasePage):
|
|||||||
@property
|
@property
|
||||||
def set_page_load_strategy(self) -> PageLoadStrategy: ...
|
def set_page_load_strategy(self) -> PageLoadStrategy: ...
|
||||||
|
|
||||||
def set_timeouts(self, implicit: float = ..., page_load: float = ..., script: float = ...) -> None: ...
|
def set_timeouts(self, implicit: float = None, page_load: float = None, script: float = None) -> None: ...
|
||||||
|
|
||||||
def run_js(self, script: str, as_expr: bool = ..., *args: Any) -> Any: ...
|
def run_js(self, script: str, as_expr: bool = False, *args: Any) -> Any: ...
|
||||||
|
|
||||||
def run_async_js(self, script: str, as_expr: bool = ..., *args: Any) -> None: ...
|
def run_async_js(self, script: str, as_expr: bool = False, *args: Any) -> None: ...
|
||||||
|
|
||||||
def get(self,
|
def get(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool = ...,
|
show_errmsg: bool = False,
|
||||||
retry: int = ...,
|
retry: int = None,
|
||||||
interval: float = ...,
|
interval: float = None,
|
||||||
timeout: float = ...) -> Union[None, bool]: ...
|
timeout: float = None) -> Union[None, bool]: ...
|
||||||
|
|
||||||
def wait_loading(self, timeout: float = ...) -> bool: ...
|
def wait_loading(self, timeout: float = 1) -> bool: ...
|
||||||
|
|
||||||
def get_cookies(self, as_dict: bool = ...) -> Union[list, dict]: ...
|
def get_cookies(self, as_dict: bool = False) -> Union[list, dict]: ...
|
||||||
|
|
||||||
def set_cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
def set_cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
||||||
|
|
||||||
@ -130,33 +130,33 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame]]: ...
|
timeout: float = None) -> List[Union[ChromiumElement, ChromiumFrame]]: ...
|
||||||
|
|
||||||
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str] = ...) \
|
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str] = None) \
|
||||||
-> Union[SessionElement, str, None]: ...
|
-> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
||||||
timeout: float = ..., single: bool = ..., relative: bool = ...) \
|
timeout: float = None, single: bool = True, relative: bool = False) \
|
||||||
-> Union[ChromiumElement, ChromiumFrame, None, List[Union[ChromiumElement, ChromiumFrame]]]: ...
|
-> Union[ChromiumElement, ChromiumFrame, None, List[Union[ChromiumElement, ChromiumFrame]]]: ...
|
||||||
|
|
||||||
def wait_ele(self,
|
def wait_ele(self,
|
||||||
loc_or_ele: Union[str, tuple, ChromiumElement],
|
loc_or_ele: Union[str, tuple, ChromiumElement],
|
||||||
timeout: float = ...) -> 'ChromiumElementWaiter': ...
|
timeout: float = None) -> 'ChromiumElementWaiter': ...
|
||||||
|
|
||||||
def scroll_to_see(self, loc_or_ele: Union[str, tuple, ChromiumElement]) -> None: ...
|
def scroll_to_see(self, loc_or_ele: Union[str, tuple, ChromiumElement]) -> None: ...
|
||||||
|
|
||||||
def refresh(self, ignore_cache: bool = ...) -> None: ...
|
def refresh(self, ignore_cache: bool = False) -> None: ...
|
||||||
|
|
||||||
def forward(self, steps: int = ...) -> None: ...
|
def forward(self, steps: int = 1) -> None: ...
|
||||||
|
|
||||||
def back(self, steps: int = ...) -> None: ...
|
def back(self, steps: int = 1) -> None: ...
|
||||||
|
|
||||||
def _forward_or_back(self, steps: int) -> None: ...
|
def _forward_or_back(self, steps: int) -> None: ...
|
||||||
|
|
||||||
@ -182,10 +182,10 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
def _d_connect(self,
|
def _d_connect(self,
|
||||||
to_url: str,
|
to_url: str,
|
||||||
times: int = ...,
|
times: int = 0,
|
||||||
interval: float = ...,
|
interval: float = 1,
|
||||||
show_errmsg: bool = ...,
|
show_errmsg: bool = False,
|
||||||
timeout: float = ...) -> Union[bool, None]: ...
|
timeout: float = None) -> Union[bool, None]: ...
|
||||||
|
|
||||||
|
|
||||||
class Timeout(object):
|
class Timeout(object):
|
||||||
|
@ -9,7 +9,7 @@ from pathlib import Path
|
|||||||
from time import perf_counter, sleep
|
from time import perf_counter, sleep
|
||||||
|
|
||||||
from .base import DrissionElement, BaseElement
|
from .base import DrissionElement, BaseElement
|
||||||
from .common import make_absolute_link, get_loc, get_ele_txt, format_html, is_js_func, _location_in_viewport
|
from .common import make_absolute_link, get_loc, get_ele_txt, format_html, is_js_func, location_in_viewport
|
||||||
from .keys import _keys_to_typing, _keyDescriptionForString, _keyDefinitions
|
from .keys import _keys_to_typing, _keyDescriptionForString, _keyDefinitions
|
||||||
from .session_element import make_session_ele
|
from .session_element import make_session_ele
|
||||||
|
|
||||||
@ -262,6 +262,14 @@ class ChromiumElement(DrissionElement):
|
|||||||
"""
|
"""
|
||||||
return super().befores(filter_loc, timeout)
|
return super().befores(filter_loc, timeout)
|
||||||
|
|
||||||
|
def afters(self, filter_loc='', timeout=None):
|
||||||
|
"""返回当前元素后面符合条件的全部兄弟元素或节点组成的列表,可用查询语法筛选。查找范围不限兄弟元素,而是整个DOM文档 \n
|
||||||
|
:param filter_loc: 用于筛选元素的查询语法
|
||||||
|
:param timeout: 查找元素的超时时间
|
||||||
|
:return: 本元素前面的元素或节点组成的列表
|
||||||
|
"""
|
||||||
|
return super().afters(filter_loc, timeout)
|
||||||
|
|
||||||
def wait_ele(self, loc_or_ele, timeout=None):
|
def wait_ele(self, loc_or_ele, timeout=None):
|
||||||
"""返回用于等待子元素到达某个状态的等待器对象 \n
|
"""返回用于等待子元素到达某个状态的等待器对象 \n
|
||||||
:param loc_or_ele: 可以是元素、查询字符串、loc元组
|
:param loc_or_ele: 可以是元素、查询字符串、loc元组
|
||||||
@ -311,7 +319,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
def is_in_viewport(self):
|
def is_in_viewport(self):
|
||||||
"""返回元素是否出现在视口中,以元素可以接受点击的点为判断"""
|
"""返回元素是否出现在视口中,以元素可以接受点击的点为判断"""
|
||||||
x, y = self.location
|
x, y = self.location
|
||||||
return _location_in_viewport(self.page, x, y) if x else False
|
return location_in_viewport(self.page, x, y) if x else False
|
||||||
|
|
||||||
def attr(self, attr):
|
def attr(self, attr):
|
||||||
"""返回attribute属性值 \n
|
"""返回attribute属性值 \n
|
||||||
@ -811,7 +819,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return self.page.run_cdp('DOM.getBoxModel', nodeId=self.node_id, not_change=True)['model'][quad]
|
return self.page.run_cdp('DOM.getBoxModel', nodeId=self.node_id, not_change=True)['model'][quad]
|
||||||
except:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _get_absolute_rect(self, x, y):
|
def _get_absolute_rect(self, x, y):
|
||||||
@ -1393,7 +1401,7 @@ def _offset_scroll(ele, offset_x, offset_y):
|
|||||||
lx = loc_x + offset_x if offset_x else cp_x
|
lx = loc_x + offset_x if offset_x else cp_x
|
||||||
ly = loc_y + offset_y if offset_y else cp_y
|
ly = loc_y + offset_y if offset_y else cp_y
|
||||||
|
|
||||||
if not _location_in_viewport(ele.page, lx, ly):
|
if not location_in_viewport(ele.page, lx, ly):
|
||||||
ele.page.scroll.to_location(lx, ly)
|
ele.page.scroll.to_location(lx, ly)
|
||||||
cl_x, cl_y = ele.client_location
|
cl_x, cl_y = ele.client_location
|
||||||
ccp_x, ccp_y = ele._client_click_point
|
ccp_x, ccp_y = ele._client_click_point
|
||||||
|
@ -18,7 +18,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
page: ChromiumBase,
|
page: ChromiumBase,
|
||||||
node_id: str = ..., obj_id: str = ..., backend_id: str = ...):
|
node_id: str = None, obj_id: str = None, backend_id: str = None):
|
||||||
self._tag: str = ...
|
self._tag: str = ...
|
||||||
self.page: Union[ChromiumPage, WebPage] = ...
|
self.page: Union[ChromiumPage, WebPage] = ...
|
||||||
self._node_id: str = ...
|
self._node_id: str = ...
|
||||||
@ -32,7 +32,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tag(self) -> str: ...
|
def tag(self) -> str: ...
|
||||||
@ -101,43 +101,47 @@ class ChromiumElement(DrissionElement):
|
|||||||
@property
|
@property
|
||||||
def scroll(self) -> ChromiumScroll: ...
|
def scroll(self) -> ChromiumScroll: ...
|
||||||
|
|
||||||
def parent(self, level_or_loc: Union[tuple, str, int] = ...) -> Union[ChromiumElement, None]: ...
|
def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union[ChromiumElement, None]: ...
|
||||||
|
|
||||||
def prev(self,
|
def prev(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union[ChromiumElement, str, None]: ...
|
timeout: float = 0) -> Union[ChromiumElement, str, None]: ...
|
||||||
|
|
||||||
def next(self,
|
def next(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union[ChromiumElement, str, None]: ...
|
timeout: float = 0) -> Union[ChromiumElement, str, None]: ...
|
||||||
|
|
||||||
def before(self,
|
def before(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union[ChromiumElement, str, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, str, None]: ...
|
||||||
|
|
||||||
def after(self,
|
def after(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union[ChromiumElement, str, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, str, None]: ...
|
||||||
|
|
||||||
def prevs(self,
|
def prevs(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, str]]: ...
|
timeout: float = 0) -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def nexts(self,
|
def nexts(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, str]]: ...
|
timeout: float = 0) -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def befores(self,
|
def befores(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, str]]: ...
|
timeout: float = None) -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
|
def afters(self,
|
||||||
|
filter_loc: Union[tuple, str] = '',
|
||||||
|
timeout: float = None) -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def wait_ele(self,
|
def wait_ele(self,
|
||||||
loc_or_ele: Union[str, tuple, ChromiumElement],
|
loc_or_ele: Union[str, tuple, ChromiumElement],
|
||||||
timeout: float = ...) -> ChromiumElementWaiter: ...
|
timeout: float = None) -> ChromiumElementWaiter: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def select(self) -> ChromiumSelect: ...
|
def select(self) -> ChromiumSelect: ...
|
||||||
@ -169,66 +173,67 @@ class ChromiumElement(DrissionElement):
|
|||||||
|
|
||||||
def set_innerHTML(self, html: str) -> None: ...
|
def set_innerHTML(self, html: str) -> None: ...
|
||||||
|
|
||||||
def run_js(self, script: str, as_expr: bool = ..., *args: Any) -> Any: ...
|
def run_js(self, script: str, as_expr: bool = False, *args: Any) -> Any: ...
|
||||||
|
|
||||||
def run_async_js(self, script: str, as_expr: bool = ..., *args: Any) -> None: ...
|
def run_async_js(self, script: str, as_expr: bool = False, *args: Any) -> None: ...
|
||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
timeout: float = None) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||||
|
|
||||||
def s_ele(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> Union[SessionElement, str, None]: ...
|
def s_ele(self, loc_or_str: Union[Tuple[str, str], str] = None) -> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = None) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ..., single: bool = ..., relative: bool = ...) \
|
timeout: float = None, single: bool = True, relative: bool = False) \
|
||||||
-> Union[ChromiumElement, ChromiumFrame, str, None, List[Union[ChromiumElement, ChromiumFrame, str]]]: ...
|
-> Union[ChromiumElement, ChromiumFrame, str, None, List[Union[ChromiumElement, ChromiumFrame, str]]]: ...
|
||||||
|
|
||||||
def style(self, style: str, pseudo_ele: str = ...) -> str: ...
|
def style(self, style: str, pseudo_ele: str = '') -> str: ...
|
||||||
|
|
||||||
def get_src(self) -> Union[bytes, str, None]: ...
|
def get_src(self) -> Union[bytes, str, None]: ...
|
||||||
|
|
||||||
def save(self, path: [str, bool] = ..., rename: str = ...) -> None: ...
|
def save(self, path: [str, bool] = None, rename: str = None) -> None: ...
|
||||||
|
|
||||||
def get_screenshot(self, path: [str, Path] = ..., as_bytes: [bool, str] = ...) -> Union[str, bytes]: ...
|
def get_screenshot(self, path: [str, Path] = None, as_bytes: [bool, str] = None) -> Union[str, bytes]: ...
|
||||||
|
|
||||||
def input(self, vals: Any, clear: bool = ...) -> None: ...
|
def input(self, vals: Any, clear: bool = True) -> None: ...
|
||||||
|
|
||||||
def _set_file_input(self, files: Union[str, list, tuple]) -> None: ...
|
def _set_file_input(self, files: Union[str, list, tuple]) -> None: ...
|
||||||
|
|
||||||
def clear(self, by_js: bool = ...) -> None: ...
|
def clear(self, by_js: bool = False) -> None: ...
|
||||||
|
|
||||||
def click(self, by_js: bool = ..., retry: bool = ..., timeout: float = ...,
|
def click(self, by_js: bool = None, retry: bool = False, timeout: float = 0.2,
|
||||||
wait_loading: Union[bool, float] = ...) -> bool: ...
|
wait_loading: Union[bool, float] = 0) -> bool: ...
|
||||||
|
|
||||||
def click_at(self, offset_x: Union[int, str] = ..., offset_y: Union[int, str] = ..., button: str = ...) -> None: ...
|
def click_at(self, offset_x: Union[int, str] = None, offset_y: Union[int, str] = None,
|
||||||
|
button: str = 'left') -> None: ...
|
||||||
|
|
||||||
def r_click(self) -> None: ...
|
def r_click(self) -> None: ...
|
||||||
|
|
||||||
def m_click(self) -> None: ...
|
def m_click(self) -> None: ...
|
||||||
|
|
||||||
def r_click_at(self, offset_x: Union[int, str] = ..., offset_y: Union[int, str] = ...) -> None: ...
|
def r_click_at(self, offset_x: Union[int, str] = None, offset_y: Union[int, str] = None) -> None: ...
|
||||||
|
|
||||||
def _click(self, client_x: int, client_y: int, button: str = ...) -> None: ...
|
def _click(self, client_x: int, client_y: int, button: str = 'left') -> None: ...
|
||||||
|
|
||||||
def hover(self, offset_x: int = ..., offset_y: int = ...) -> None: ...
|
def hover(self, offset_x: int = None, offset_y: int = None) -> None: ...
|
||||||
|
|
||||||
def drag(self, offset_x: int = ..., offset_y: int = ..., speed: int = ..., shake: bool = ...) -> None: ...
|
def drag(self, offset_x: int = 0, offset_y: int = 0, speed: int = 40, shake: bool = True) -> None: ...
|
||||||
|
|
||||||
def drag_to(self,
|
def drag_to(self,
|
||||||
ele_or_loc: Union[tuple, ChromiumElement],
|
ele_or_loc: Union[tuple, ChromiumElement],
|
||||||
speed: int = ...,
|
speed: int = 40,
|
||||||
shake: bool = ...) -> None: ...
|
shake: bool = True) -> None: ...
|
||||||
|
|
||||||
def _get_obj_id(self, node_id: str = ..., backend_id: str = ...) -> str: ...
|
def _get_obj_id(self, node_id: str = None, backend_id: str = None) -> str: ...
|
||||||
|
|
||||||
def _get_node_id(self, obj_id: str = ..., backend_id: str = ...) -> str: ...
|
def _get_node_id(self, obj_id: str = None, backend_id: str = None) -> str: ...
|
||||||
|
|
||||||
def _get_backend_id(self, node_id: str) -> str: ...
|
def _get_backend_id(self, node_id: str) -> str: ...
|
||||||
|
|
||||||
@ -243,8 +248,8 @@ class ChromiumShadowRootElement(BaseElement):
|
|||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
parent_ele: ChromiumElement,
|
parent_ele: ChromiumElement,
|
||||||
obj_id: str = ...,
|
obj_id: str = None,
|
||||||
backend_id: str = ...):
|
backend_id: str = None):
|
||||||
self._obj_id: str = ...
|
self._obj_id: str = ...
|
||||||
self._node_id: str = ...
|
self._node_id: str = ...
|
||||||
self._backend_id: str = ...
|
self._backend_id: str = ...
|
||||||
@ -255,7 +260,7 @@ class ChromiumShadowRootElement(BaseElement):
|
|||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, None]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_enabled(self) -> bool: ...
|
def is_enabled(self) -> bool: ...
|
||||||
@ -281,46 +286,46 @@ class ChromiumShadowRootElement(BaseElement):
|
|||||||
@property
|
@property
|
||||||
def inner_html(self) -> str: ...
|
def inner_html(self) -> str: ...
|
||||||
|
|
||||||
def run_js(self, script: str, as_expr: bool = ..., *args: Any) -> Any: ...
|
def run_js(self, script: str, as_expr: bool = False, *args: Any) -> Any: ...
|
||||||
|
|
||||||
def run_async_js(self, script: str, as_expr: bool = ..., *args: Any) -> None: ...
|
def run_async_js(self, script: str, as_expr: bool = False, *args: Any) -> None: ...
|
||||||
|
|
||||||
def parent(self, level_or_loc: Union[str, int] = ...) -> ChromiumElement: ...
|
def parent(self, level_or_loc: Union[str, int] = 1) -> ChromiumElement: ...
|
||||||
|
|
||||||
def next(self,
|
def next(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...) -> Union[ChromiumElement, str, None]: ...
|
index: int = 1) -> Union[ChromiumElement, str, None]: ...
|
||||||
|
|
||||||
def before(self,
|
def before(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...) -> Union[ChromiumElement, str, None]: ...
|
index: int = 1) -> Union[ChromiumElement, str, None]: ...
|
||||||
|
|
||||||
def after(self,
|
def after(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...) -> Union[ChromiumElement, str, None]: ...
|
index: int = 1) -> Union[ChromiumElement, str, None]: ...
|
||||||
|
|
||||||
def nexts(self, filter_loc: Union[tuple, str] = ...) -> List[Union[ChromiumElement, str]]: ...
|
def nexts(self, filter_loc: Union[tuple, str] = '') -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def befores(self, filter_loc: Union[tuple, str] = ...) -> List[Union[ChromiumElement, str]]: ...
|
def befores(self, filter_loc: Union[tuple, str] = '') -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def afters(self, filter_loc: Union[tuple, str] = ...) -> List[Union[ChromiumElement, str]]: ...
|
def afters(self, filter_loc: Union[tuple, str] = '') -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame]]: ...
|
timeout: float = None) -> List[Union[ChromiumElement, ChromiumFrame]]: ...
|
||||||
|
|
||||||
def s_ele(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> Union[SessionElement, str, None]: ...
|
def s_ele(self, loc_or_str: Union[Tuple[str, str], str] = None) -> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...,
|
timeout: float = None,
|
||||||
single: bool = ..., relative: bool = ...) \
|
single: bool = True, relative: bool = False) \
|
||||||
-> Union[ChromiumElement, ChromiumFrame, None, str, List[Union[ChromiumElement, ChromiumFrame, str]]]: ...
|
-> Union[ChromiumElement, ChromiumFrame, None, str, List[Union[ChromiumElement, ChromiumFrame, str]]]: ...
|
||||||
|
|
||||||
def _get_node_id(self, obj_id: str) -> str: ...
|
def _get_node_id(self, obj_id: str) -> str: ...
|
||||||
@ -332,9 +337,9 @@ class ChromiumShadowRootElement(BaseElement):
|
|||||||
|
|
||||||
def find_in_chromium_ele(ele: ChromiumElement,
|
def find_in_chromium_ele(ele: ChromiumElement,
|
||||||
loc: Union[str, Tuple[str, str]],
|
loc: Union[str, Tuple[str, str]],
|
||||||
single: bool = ...,
|
single: bool = True,
|
||||||
timeout: float = ...,
|
timeout: float = None,
|
||||||
relative: bool = ...) -> Union[
|
relative: bool = True) -> Union[
|
||||||
ChromiumElement, str, None, List[Union[ChromiumElement, str]]]: ...
|
ChromiumElement, str, None, List[Union[ChromiumElement, str]]]: ...
|
||||||
|
|
||||||
|
|
||||||
@ -342,7 +347,7 @@ def _find_by_xpath(ele: ChromiumElement,
|
|||||||
xpath: str,
|
xpath: str,
|
||||||
single: bool,
|
single: bool,
|
||||||
timeout: float,
|
timeout: float,
|
||||||
relative: bool = ...) -> Union[ChromiumElement, List[ChromiumElement], None]: ...
|
relative: bool = True) -> Union[ChromiumElement, List[ChromiumElement], None]: ...
|
||||||
|
|
||||||
|
|
||||||
def _find_by_css(ele: ChromiumElement,
|
def _find_by_css(ele: ChromiumElement,
|
||||||
@ -359,7 +364,7 @@ def _make_js_for_find_ele_by_xpath(xpath: str, type_txt: str, node_txt: str) ->
|
|||||||
|
|
||||||
|
|
||||||
def run_js(page_or_ele: Union[ChromiumBase, ChromiumElement, ChromiumShadowRootElement], script: str,
|
def run_js(page_or_ele: Union[ChromiumBase, ChromiumElement, ChromiumShadowRootElement], script: str,
|
||||||
as_expr: bool = ..., timeout: float = ..., args: tuple = ..., not_change: bool = ...) -> Any: ...
|
as_expr: bool = False, timeout: float = None, args: tuple = ..., not_change: bool = ...) -> Any: ...
|
||||||
|
|
||||||
|
|
||||||
def _parse_js_result(page: ChromiumBase, ele: ChromiumElement, result: dict): ...
|
def _parse_js_result(page: ChromiumBase, ele: ChromiumElement, result: dict): ...
|
||||||
@ -398,13 +403,13 @@ class ChromiumScroll(object):
|
|||||||
|
|
||||||
def to_location(self, x: int, y: int) -> None: ...
|
def to_location(self, x: int, y: int) -> None: ...
|
||||||
|
|
||||||
def up(self, pixel: int = ...) -> None: ...
|
def up(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
def down(self, pixel: int = ...) -> None: ...
|
def down(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
def left(self, pixel: int = ...) -> None: ...
|
def left(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
def right(self, pixel: int = ...) -> None: ...
|
def right(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class ChromiumSelect(object):
|
class ChromiumSelect(object):
|
||||||
@ -428,30 +433,30 @@ class ChromiumSelect(object):
|
|||||||
|
|
||||||
def clear(self) -> None: ...
|
def clear(self) -> None: ...
|
||||||
|
|
||||||
def by_text(self, text: Union[str, list, tuple], timeout: float = ...) -> bool: ...
|
def by_text(self, text: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def by_value(self, value: Union[str, list, tuple], timeout: float = ...) -> bool: ...
|
def by_value(self, value: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def by_index(self, index: Union[int, list, tuple], timeout: float = ...) -> bool: ...
|
def by_index(self, index: Union[int, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def cancel_by_text(self, text: Union[str, list, tuple], timeout: float = ...) -> bool: ...
|
def cancel_by_text(self, text: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def cancel_by_value(self, value: Union[str, list, tuple], timeout: float = ...) -> bool: ...
|
def cancel_by_value(self, value: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def cancel_by_index(self, index: Union[int, list, tuple], timeout: float = ...) -> bool: ...
|
def cancel_by_index(self, index: Union[int, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def invert(self) -> None: ...
|
def invert(self) -> None: ...
|
||||||
|
|
||||||
def _select(self,
|
def _select(self,
|
||||||
text_value_index: Union[str, int, list, tuple] = ...,
|
text_value_index: Union[str, int, list, tuple] = None,
|
||||||
para_type: str = ...,
|
para_type: str = 'text',
|
||||||
deselect: bool = ...,
|
deselect: bool = False,
|
||||||
timeout: float = ...) -> bool: ...
|
timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def _select_multi(self,
|
def _select_multi(self,
|
||||||
text_value_index: Union[list, tuple] = ...,
|
text_value_index: Union[list, tuple] = None,
|
||||||
para_type: str = ...,
|
para_type: str = 'text',
|
||||||
deselect: bool = ...) -> bool: ...
|
deselect: bool = False) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementWaiter(object):
|
class ChromiumElementWaiter(object):
|
||||||
@ -459,7 +464,7 @@ class ChromiumElementWaiter(object):
|
|||||||
def __init__(self,
|
def __init__(self,
|
||||||
page_or_ele: Union[ChromiumBase, ChromiumElement],
|
page_or_ele: Union[ChromiumBase, ChromiumElement],
|
||||||
loc_or_ele: Union[str, tuple, ChromiumElement],
|
loc_or_ele: Union[str, tuple, ChromiumElement],
|
||||||
timeout: float = ...):
|
timeout: float = None):
|
||||||
self.loc_or_ele: Union[str, tuple, ChromiumElement] = ...
|
self.loc_or_ele: Union[str, tuple, ChromiumElement] = ...
|
||||||
self.timeout: float = ...
|
self.timeout: float = ...
|
||||||
self.driver: Union[ChromiumPage, ChromiumPage] = ...
|
self.driver: Union[ChromiumPage, ChromiumPage] = ...
|
||||||
|
@ -64,7 +64,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self._tab_obj.DOM.describeNode(nodeId=self.node_id)
|
self._tab_obj.DOM.describeNode(nodeId=self.node_id)
|
||||||
except:
|
except Exception:
|
||||||
self._reload()
|
self._reload()
|
||||||
sleep(2)
|
sleep(2)
|
||||||
|
|
||||||
@ -359,6 +359,15 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
self._check_ok()
|
self._check_ok()
|
||||||
return self.frame_ele.befores(filter_loc, timeout)
|
return self.frame_ele.befores(filter_loc, timeout)
|
||||||
|
|
||||||
|
def afters(self, filter_loc='', timeout=None):
|
||||||
|
"""返回当前元素后面符合条件的全部兄弟元素或节点组成的列表,可用查询语法筛选。查找范围不限兄弟元素,而是整个DOM文档 \n
|
||||||
|
:param filter_loc: 用于筛选元素的查询语法
|
||||||
|
:param timeout: 查找元素的超时时间
|
||||||
|
:return: 本元素前面的元素或节点组成的列表
|
||||||
|
"""
|
||||||
|
self._check_ok()
|
||||||
|
return self.frame_ele.afters(filter_loc, timeout)
|
||||||
|
|
||||||
def _ele(self, loc_or_ele, timeout=None, single=True, relative=False):
|
def _ele(self, loc_or_ele, timeout=None, single=True, relative=False):
|
||||||
"""在frame内查找单个元素 \n
|
"""在frame内查找单个元素 \n
|
||||||
:param loc_or_ele: 定位符或元素对象
|
:param loc_or_ele: 定位符或元素对象
|
||||||
|
@ -24,7 +24,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||||
|
|
||||||
def __repr__(self) -> str: ...
|
def __repr__(self) -> str: ...
|
||||||
|
|
||||||
@ -103,52 +103,56 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
|
|
||||||
def remove_attr(self, attr: str) -> None: ...
|
def remove_attr(self, attr: str) -> None: ...
|
||||||
|
|
||||||
def run_js(self, script: str, as_expr: bool = ..., *args: Any) -> Any: ...
|
def run_js(self, script: str, as_expr: bool = False, *args: Any) -> Any: ...
|
||||||
|
|
||||||
def parent(self, level_or_loc: Union[tuple, str, int] = ...) -> Union[ChromiumElement, None]: ...
|
def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union[ChromiumElement, None]: ...
|
||||||
|
|
||||||
def prev(self,
|
def prev(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
timeout: float = 0) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||||
|
|
||||||
def next(self,
|
def next(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
timeout: float = 0) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||||
|
|
||||||
def before(self,
|
def before(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||||
|
|
||||||
def after(self,
|
def after(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||||
|
|
||||||
def prevs(self,
|
def prevs(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
timeout: float = 0) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||||
|
|
||||||
def nexts(self,
|
def nexts(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
timeout: float = 0) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||||
|
|
||||||
def befores(self,
|
def befores(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = ...,
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||||
|
|
||||||
|
def afters(self,
|
||||||
|
filter_loc: Union[tuple, str] = ...,
|
||||||
|
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
||||||
timeout: float = ..., single: bool = ..., relative: bool = ...) \
|
timeout: float = None, single: bool = True, relative: bool = False) \
|
||||||
-> Union[ChromiumElement, ChromiumFrame, None, List[Union[ChromiumElement, ChromiumFrame]]]: ...
|
-> Union[ChromiumElement, ChromiumFrame, None, List[Union[ChromiumElement, ChromiumFrame]]]: ...
|
||||||
|
|
||||||
def _d_connect(self,
|
def _d_connect(self,
|
||||||
to_url: str,
|
to_url: str,
|
||||||
times: int = ...,
|
times: int = 0,
|
||||||
interval: float = ...,
|
interval: float = 1,
|
||||||
show_errmsg: bool = ...,
|
show_errmsg: bool = False,
|
||||||
timeout: float = ...) -> Union[bool, None]: ...
|
timeout: float = None) -> Union[bool, None]: ...
|
||||||
|
|
||||||
def _is_inner_frame(self) -> bool: ...
|
def _is_inner_frame(self) -> bool: ...
|
||||||
|
@ -16,9 +16,9 @@ from .chromium_driver import ChromiumDriver
|
|||||||
class ChromiumPage(ChromiumBase):
|
class ChromiumPage(ChromiumBase):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
addr_driver_opts: Union[str, ChromiumDriver, DriverOptions] = ...,
|
addr_driver_opts: Union[str, ChromiumDriver, DriverOptions] = None,
|
||||||
tab_id: str = ...,
|
tab_id: str = None,
|
||||||
timeout: float = ...):
|
timeout: float = None):
|
||||||
self.options: DriverOptions = ...
|
self.options: DriverOptions = ...
|
||||||
self.process: popen = ...
|
self.process: popen = ...
|
||||||
self._window_setter: WindowSetter = ...
|
self._window_setter: WindowSetter = ...
|
||||||
@ -26,10 +26,10 @@ class ChromiumPage(ChromiumBase):
|
|||||||
self._alert: Alert = ...
|
self._alert: Alert = ...
|
||||||
|
|
||||||
def _connect_browser(self,
|
def _connect_browser(self,
|
||||||
addr_driver_opts: Union[str, ChromiumDriver, DriverOptions] = ...,
|
addr_driver_opts: Union[str, ChromiumDriver, DriverOptions] = None,
|
||||||
tab_id: str = ...) -> None: ...
|
tab_id: str = None) -> None: ...
|
||||||
|
|
||||||
def _init_page(self, tab_id: str = ...) -> None: ...
|
def _init_page(self, tab_id: str = None) -> None: ...
|
||||||
|
|
||||||
def _set_options(self) -> None: ...
|
def _set_options(self) -> None: ...
|
||||||
|
|
||||||
@ -48,29 +48,29 @@ class ChromiumPage(ChromiumBase):
|
|||||||
@property
|
@property
|
||||||
def set_window(self) -> 'WindowSetter': ...
|
def set_window(self) -> 'WindowSetter': ...
|
||||||
|
|
||||||
def get_tab(self, tab_id: str = ...) -> ChromiumTab: ...
|
def get_tab(self, tab_id: str = None) -> ChromiumTab: ...
|
||||||
|
|
||||||
def get_screenshot(self, path: [str, Path] = ...,
|
def get_screenshot(self, path: [str, Path] = None,
|
||||||
as_bytes: [bool, str] = ...,
|
as_bytes: [bool, str] = None,
|
||||||
full_page: bool = ...,
|
full_page: bool = False,
|
||||||
left_top: Tuple[int, int] = ...,
|
left_top: Tuple[int, int] = None,
|
||||||
right_bottom: Tuple[int, int] = ...) -> Union[str, bytes]: ...
|
right_bottom: Tuple[int, int] = None) -> Union[str, bytes]: ...
|
||||||
|
|
||||||
def to_front(self) -> None: ...
|
def to_front(self) -> None: ...
|
||||||
|
|
||||||
def new_tab(self, url: str = ..., switch_to: bool = ...) -> None: ...
|
def new_tab(self, url: str = None, switch_to: bool = True) -> None: ...
|
||||||
|
|
||||||
def to_main_tab(self) -> None: ...
|
def to_main_tab(self) -> None: ...
|
||||||
|
|
||||||
def to_tab(self, tab_id: str = ..., activate: bool = ...) -> None: ...
|
def to_tab(self, tab_id: str = None, activate: bool = True) -> None: ...
|
||||||
|
|
||||||
def _to_tab(self, tab_id: str = ..., activate: bool = ..., read_doc: bool = ...) -> None: ...
|
def _to_tab(self, tab_id: str = None, activate: bool = True, read_doc: bool = True) -> None: ...
|
||||||
|
|
||||||
def close_tabs(self, tab_ids: Union[str, List[str], Tuple[str]] = ..., others: bool = ...) -> None: ...
|
def close_tabs(self, tab_ids: Union[str, List[str], Tuple[str]] = None, others: bool = False) -> None: ...
|
||||||
|
|
||||||
def close_other_tabs(self, tab_ids: Union[str, List[str], Tuple[str]] = ...) -> None: ...
|
def close_other_tabs(self, tab_ids: Union[str, List[str], Tuple[str]] = None) -> None: ...
|
||||||
|
|
||||||
def handle_alert(self, accept: bool = ..., send: str = ..., timeout: float = ...) -> Union[str, None]: ...
|
def handle_alert(self, accept: bool = True, send: str = None, timeout: float = None) -> Union[str, None]: ...
|
||||||
|
|
||||||
def hide_browser(self) -> None: ...
|
def hide_browser(self) -> None: ...
|
||||||
|
|
||||||
@ -108,16 +108,16 @@ class WindowSetter(object):
|
|||||||
|
|
||||||
def normal(self) -> None: ...
|
def normal(self) -> None: ...
|
||||||
|
|
||||||
def size(self, width: int = ..., height: int = ...) -> None: ...
|
def size(self, width: int = None, height: int = None) -> None: ...
|
||||||
|
|
||||||
def location(self, x: int = ..., y: int = ...) -> None: ...
|
def location(self, x: int = None, y: int = None) -> None: ...
|
||||||
|
|
||||||
def _get_info(self) -> dict: ...
|
def _get_info(self) -> dict: ...
|
||||||
|
|
||||||
def _perform(self, bounds: dict) -> None: ...
|
def _perform(self, bounds: dict) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
def show_or_hide_browser(page: ChromiumPage, hide: bool = ...) -> None: ...
|
def show_or_hide_browser(page: ChromiumPage, hide: bool = True) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
def get_browser_progress_id(progress: Union[popen, None], address: str) -> Union[str, None]: ...
|
def get_browser_progress_id(progress: Union[popen, None], address: str) -> Union[str, None]: ...
|
||||||
|
@ -9,7 +9,7 @@ from .chromium_page import ChromiumPage
|
|||||||
|
|
||||||
class ChromiumTab(ChromiumBase):
|
class ChromiumTab(ChromiumBase):
|
||||||
|
|
||||||
def __init__(self, page:ChromiumPage, tab_id: str = ...):
|
def __init__(self, page: ChromiumPage, tab_id: str = None):
|
||||||
self.page: ChromiumPage = ...
|
self.page: ChromiumPage = ...
|
||||||
|
|
||||||
def _set_options(self) -> None: ...
|
def _set_options(self) -> None: ...
|
||||||
|
@ -18,7 +18,7 @@ from requests import get as requests_get
|
|||||||
from .config import DriverOptions
|
from .config import DriverOptions
|
||||||
|
|
||||||
|
|
||||||
def get_ele_txt(e) -> str:
|
def get_ele_txt(e):
|
||||||
"""获取元素内所有文本
|
"""获取元素内所有文本
|
||||||
:param e: 元素对象
|
:param e: 元素对象
|
||||||
:return: 元素内所有文本
|
:return: 元素内所有文本
|
||||||
@ -85,7 +85,7 @@ def get_ele_txt(e) -> str:
|
|||||||
return format_html(re_str)
|
return format_html(re_str)
|
||||||
|
|
||||||
|
|
||||||
def get_loc(loc: Union[tuple, str], translate_css: bool = False) -> tuple:
|
def get_loc(loc, translate_css=False):
|
||||||
"""接收selenium定位元组或本库定位语法,转换为标准定位元组,可翻译css selector为xpath \n
|
"""接收selenium定位元组或本库定位语法,转换为标准定位元组,可翻译css selector为xpath \n
|
||||||
:param loc: selenium定位元组或本库定位语法
|
:param loc: selenium定位元组或本库定位语法
|
||||||
:param translate_css: 是否翻译css selector为xpath
|
:param translate_css: 是否翻译css selector为xpath
|
||||||
@ -112,7 +112,7 @@ def get_loc(loc: Union[tuple, str], translate_css: bool = False) -> tuple:
|
|||||||
return loc
|
return loc
|
||||||
|
|
||||||
|
|
||||||
def str_to_loc(loc: str) -> tuple:
|
def str_to_loc(loc):
|
||||||
"""处理元素查找语句 \n
|
"""处理元素查找语句 \n
|
||||||
查找方式:属性、tag name及属性、文本、xpath、css selector、id、class \n
|
查找方式:属性、tag name及属性、文本、xpath、css selector、id、class \n
|
||||||
@表示属性,.表示class,#表示id,=表示精确匹配,:表示模糊匹配,无控制字符串时默认搜索该字符串 \n
|
@表示属性,.表示class,#表示id,=表示精确匹配,:表示模糊匹配,无控制字符串时默认搜索该字符串 \n
|
||||||
@ -280,7 +280,7 @@ def _make_search_str(search_str: str) -> str:
|
|||||||
return search_str
|
return search_str
|
||||||
|
|
||||||
|
|
||||||
def translate_loc(loc: tuple) -> tuple:
|
def translate_loc(loc):
|
||||||
"""把By类型的loc元组转换为css selector或xpath类型的 \n
|
"""把By类型的loc元组转换为css selector或xpath类型的 \n
|
||||||
:param loc: By类型的loc元组
|
:param loc: By类型的loc元组
|
||||||
:return: css selector或xpath类型的loc元组
|
:return: css selector或xpath类型的loc元组
|
||||||
@ -322,7 +322,7 @@ def translate_loc(loc: tuple) -> tuple:
|
|||||||
return loc_by, loc_str
|
return loc_by, loc_str
|
||||||
|
|
||||||
|
|
||||||
def format_html(text: str) -> str:
|
def format_html(text):
|
||||||
"""处理html编码字符 \n
|
"""处理html编码字符 \n
|
||||||
:param text: html文本
|
:param text: html文本
|
||||||
:return: 格式化后的html文本
|
:return: 格式化后的html文本
|
||||||
@ -330,7 +330,7 @@ def format_html(text: str) -> str:
|
|||||||
return unescape(text).replace('\xa0', ' ') if text else text
|
return unescape(text).replace('\xa0', ' ') if text else text
|
||||||
|
|
||||||
|
|
||||||
def clean_folder(folder_path: str, ignore: list = None) -> None:
|
def clean_folder(folder_path, ignore=None):
|
||||||
"""清空一个文件夹,除了ignore里的文件和文件夹 \n
|
"""清空一个文件夹,除了ignore里的文件和文件夹 \n
|
||||||
:param folder_path: 要清空的文件夹路径
|
:param folder_path: 要清空的文件夹路径
|
||||||
:param ignore: 忽略列表
|
:param ignore: 忽略列表
|
||||||
@ -347,7 +347,7 @@ def clean_folder(folder_path: str, ignore: list = None) -> None:
|
|||||||
rmtree(f, True)
|
rmtree(f, True)
|
||||||
|
|
||||||
|
|
||||||
def unzip(zip_path: str, to_path: str) -> Union[list, None]:
|
def unzip(zip_path, to_path):
|
||||||
"""解压下载的chromedriver.zip文件"""
|
"""解压下载的chromedriver.zip文件"""
|
||||||
if not zip_path:
|
if not zip_path:
|
||||||
return
|
return
|
||||||
@ -356,7 +356,7 @@ def unzip(zip_path: str, to_path: str) -> Union[list, None]:
|
|||||||
return [f.extract(f.namelist()[0], path=to_path)]
|
return [f.extract(f.namelist()[0], path=to_path)]
|
||||||
|
|
||||||
|
|
||||||
def get_exe_path_from_port(port: Union[str, int]) -> Union[str, None]:
|
def get_exe_path_from_port(port):
|
||||||
"""获取端口号第一条进程的可执行文件路径 \n
|
"""获取端口号第一条进程的可执行文件路径 \n
|
||||||
:param port: 端口号
|
:param port: 端口号
|
||||||
:return: 可执行文件的绝对路径
|
:return: 可执行文件的绝对路径
|
||||||
@ -371,7 +371,7 @@ def get_exe_path_from_port(port: Union[str, int]) -> Union[str, None]:
|
|||||||
return file_lst[2].strip() if len(file_lst) > 2 else None
|
return file_lst[2].strip() if len(file_lst) > 2 else None
|
||||||
|
|
||||||
|
|
||||||
def get_pid_from_port(port: Union[str, int]) -> Union[str, None]:
|
def get_pid_from_port(port):
|
||||||
"""获取端口号第一条进程的pid \n
|
"""获取端口号第一条进程的pid \n
|
||||||
:param port: 端口号
|
:param port: 端口号
|
||||||
:return: 进程id
|
:return: 进程id
|
||||||
@ -396,7 +396,7 @@ def get_pid_from_port(port: Union[str, int]) -> Union[str, None]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_usable_path(path: Union[str, Path]) -> Path:
|
def get_usable_path(path):
|
||||||
"""检查文件或文件夹是否有重名,并返回可以使用的路径 \n
|
"""检查文件或文件夹是否有重名,并返回可以使用的路径 \n
|
||||||
:param path: 文件或文件夹路径
|
:param path: 文件或文件夹路径
|
||||||
:return: 可用的路径,Path对象
|
:return: 可用的路径,Path对象
|
||||||
@ -424,7 +424,7 @@ def get_usable_path(path: Union[str, Path]) -> Path:
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def make_valid_name(full_name: str) -> str:
|
def make_valid_name(full_name):
|
||||||
"""获取有效的文件名 \n
|
"""获取有效的文件名 \n
|
||||||
:param full_name: 文件名
|
:param full_name: 文件名
|
||||||
:return: 可用的文件名
|
:return: 可用的文件名
|
||||||
@ -450,7 +450,7 @@ def make_valid_name(full_name: str) -> str:
|
|||||||
return sub(r'[<>/\\|:*?\n]', '', full_name)
|
return sub(r'[<>/\\|:*?\n]', '', full_name)
|
||||||
|
|
||||||
|
|
||||||
def get_long(txt) -> int:
|
def get_long(txt):
|
||||||
"""返回字符串中字符个数(一个汉字是2个字符) \n
|
"""返回字符串中字符个数(一个汉字是2个字符) \n
|
||||||
:param txt: 字符串
|
:param txt: 字符串
|
||||||
:return: 字符个数
|
:return: 字符个数
|
||||||
@ -459,7 +459,7 @@ def get_long(txt) -> int:
|
|||||||
return int((len(txt.encode('utf-8')) - txt_len) / 2 + txt_len)
|
return int((len(txt.encode('utf-8')) - txt_len) / 2 + txt_len)
|
||||||
|
|
||||||
|
|
||||||
def make_absolute_link(link, page=None) -> str:
|
def make_absolute_link(link, page=None):
|
||||||
"""获取绝对url
|
"""获取绝对url
|
||||||
:param link: 超链接
|
:param link: 超链接
|
||||||
:param page: 页面对象
|
:param page: 页面对象
|
||||||
@ -484,7 +484,7 @@ def make_absolute_link(link, page=None) -> str:
|
|||||||
return link
|
return link
|
||||||
|
|
||||||
|
|
||||||
def is_js_func(func: str) -> bool:
|
def is_js_func(func):
|
||||||
"""检查文本是否js函数"""
|
"""检查文本是否js函数"""
|
||||||
func = func.strip()
|
func = func.strip()
|
||||||
if func.startswith('function') or func.startswith('async '):
|
if func.startswith('function') or func.startswith('async '):
|
||||||
@ -514,7 +514,7 @@ def _port_is_using(ip: str, port: str) -> Union[bool, None]:
|
|||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
def connect_chrome(option: DriverOptions) -> tuple:
|
def connect_chrome(option):
|
||||||
"""连接或启动chrome \n
|
"""连接或启动chrome \n
|
||||||
:param option: DriverOptions对象
|
:param option: DriverOptions对象
|
||||||
:return: chrome 路径和进程对象组成的元组
|
:return: chrome 路径和进程对象组成的元组
|
||||||
@ -543,8 +543,8 @@ def connect_chrome(option: DriverOptions) -> tuple:
|
|||||||
|
|
||||||
# 传入的路径找不到,主动在ini文件、注册表、系统变量中找
|
# 传入的路径找不到,主动在ini文件、注册表、系统变量中找
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
from DrissionPage.easy_set import _get_chrome_path
|
from DrissionPage.easy_set import get_chrome_path
|
||||||
chrome_path = _get_chrome_path(show_msg=False)
|
chrome_path = get_chrome_path(show_msg=False)
|
||||||
|
|
||||||
if not chrome_path:
|
if not chrome_path:
|
||||||
raise FileNotFoundError('无法找到chrome路径,请手动配置。')
|
raise FileNotFoundError('无法找到chrome路径,请手动配置。')
|
||||||
@ -659,7 +659,7 @@ def _set_value_to_dict(target_dict: dict, src: list, value) -> None:
|
|||||||
exec(src)
|
exec(src)
|
||||||
|
|
||||||
|
|
||||||
def _location_in_viewport(page, loc_x: int, loc_y: int) -> bool:
|
def location_in_viewport(page, loc_x, loc_y):
|
||||||
"""判断给定的坐标是否在视口中 |n
|
"""判断给定的坐标是否在视口中 |n
|
||||||
:param page: ChromePage对象
|
:param page: ChromePage对象
|
||||||
:param loc_x: 页面绝对坐标x
|
:param loc_x: 页面绝对坐标x
|
||||||
|
59
DrissionPage/common.pyi
Normal file
59
DrissionPage/common.pyi
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""
|
||||||
|
@Author : g1879
|
||||||
|
@Contact : g1879@qq.com
|
||||||
|
"""
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Union
|
||||||
|
from requests import get as requests_get
|
||||||
|
|
||||||
|
from .base import BasePage, DrissionElement
|
||||||
|
from .config import DriverOptions
|
||||||
|
|
||||||
|
|
||||||
|
def get_ele_txt(e: DrissionElement) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
|
def get_loc(loc: Union[tuple, str], translate_css: bool = False) -> tuple: ...
|
||||||
|
|
||||||
|
|
||||||
|
def str_to_loc(loc: str) -> tuple: ...
|
||||||
|
|
||||||
|
|
||||||
|
def translate_loc(loc: tuple) -> tuple: ...
|
||||||
|
|
||||||
|
|
||||||
|
def format_html(text: str) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
|
def clean_folder(folder_path: str, ignore: list = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def unzip(zip_path: str, to_path: str) -> Union[list, None]: ...
|
||||||
|
|
||||||
|
|
||||||
|
def get_exe_path_from_port(port: Union[str, int]) -> Union[str, None]: ...
|
||||||
|
|
||||||
|
|
||||||
|
def get_pid_from_port(port: Union[str, int]) -> Union[str, None]: ...
|
||||||
|
|
||||||
|
|
||||||
|
def get_usable_path(path: Union[str, Path]) -> Path: ...
|
||||||
|
|
||||||
|
|
||||||
|
def make_valid_name(full_name: str) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
|
def get_long(txt) -> int: ...
|
||||||
|
|
||||||
|
|
||||||
|
def make_absolute_link(link, page: BasePage = None) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
|
def is_js_func(func: str) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
|
def connect_chrome(option: DriverOptions) -> tuple: ...
|
||||||
|
|
||||||
|
|
||||||
|
def location_in_viewport(page, loc_x: int, loc_y: int) -> bool: ...
|
@ -13,7 +13,7 @@ from selenium.webdriver.chrome.options import Options
|
|||||||
|
|
||||||
class OptionsManager(object):
|
class OptionsManager(object):
|
||||||
|
|
||||||
def __init__(self, path: str = ...):
|
def __init__(self, path: str = None):
|
||||||
self.ini_path: str = ...
|
self.ini_path: str = ...
|
||||||
self._conf: RawConfigParser = ...
|
self._conf: RawConfigParser = ...
|
||||||
self._paths: dict = ...
|
self._paths: dict = ...
|
||||||
@ -37,13 +37,13 @@ class OptionsManager(object):
|
|||||||
|
|
||||||
def set_item(self, section: str, item: str, value: Any) -> OptionsManager: ...
|
def set_item(self, section: str, item: str, value: Any) -> OptionsManager: ...
|
||||||
|
|
||||||
def save(self, path: str = ...) -> str: ...
|
def save(self, path: str = None) -> str: ...
|
||||||
|
|
||||||
def save_to_default(self) -> str: ...
|
def save_to_default(self) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
class SessionOptions(object):
|
class SessionOptions(object):
|
||||||
def __init__(self, read_file: bool = ..., ini_path: str = ...):
|
def __init__(self, read_file: bool = True, ini_path: str = None):
|
||||||
self.ini_path: str = ...
|
self.ini_path: str = ...
|
||||||
self._headers: dict = ...
|
self._headers: dict = ...
|
||||||
self._cookies: list = ...
|
self._cookies: list = ...
|
||||||
@ -138,7 +138,7 @@ class SessionOptions(object):
|
|||||||
|
|
||||||
def set_proxies(self, proxies: dict) -> 'SessionOptions': ...
|
def set_proxies(self, proxies: dict) -> 'SessionOptions': ...
|
||||||
|
|
||||||
def save(self, path: str = ...) -> str: ...
|
def save(self, path: str = None) -> str: ...
|
||||||
|
|
||||||
def save_to_default(self) -> str: ...
|
def save_to_default(self) -> str: ...
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class SessionOptions(object):
|
|||||||
|
|
||||||
class DriverOptions(Options):
|
class DriverOptions(Options):
|
||||||
|
|
||||||
def __init__(self, read_file: bool = ..., ini_path: str = ...):
|
def __init__(self, read_file: bool = True, ini_path: str = None):
|
||||||
self.ini_path: str = ...
|
self.ini_path: str = ...
|
||||||
self._driver_path: str = ...
|
self._driver_path: str = ...
|
||||||
self._user_data_path: str = ...
|
self._user_data_path: str = ...
|
||||||
@ -174,7 +174,7 @@ class DriverOptions(Options):
|
|||||||
|
|
||||||
# -------------重写父类方法结束-------------
|
# -------------重写父类方法结束-------------
|
||||||
|
|
||||||
def save(self, path: str = ...) -> str: ...
|
def save(self, path: str = None) -> str: ...
|
||||||
|
|
||||||
def save_to_default(self) -> str: ...
|
def save_to_default(self) -> str: ...
|
||||||
|
|
||||||
@ -186,15 +186,15 @@ class DriverOptions(Options):
|
|||||||
|
|
||||||
def set_argument(self, arg: str, value: Union[bool, str]) -> 'DriverOptions': ...
|
def set_argument(self, arg: str, value: Union[bool, str]) -> 'DriverOptions': ...
|
||||||
|
|
||||||
def set_timeouts(self, implicit: float = ..., pageLoad: float = ..., script: float = ...) -> 'DriverOptions': ...
|
def set_timeouts(self, implicit: float = None, pageLoad: float = None, script: float = None) -> 'DriverOptions': ...
|
||||||
|
|
||||||
def set_headless(self, on_off: bool = ...) -> 'DriverOptions': ...
|
def set_headless(self, on_off: bool = True) -> 'DriverOptions': ...
|
||||||
|
|
||||||
def set_no_imgs(self, on_off: bool = ...) -> 'DriverOptions': ...
|
def set_no_imgs(self, on_off: bool = True) -> 'DriverOptions': ...
|
||||||
|
|
||||||
def set_no_js(self, on_off: bool = ...) -> 'DriverOptions': ...
|
def set_no_js(self, on_off: bool = True) -> 'DriverOptions': ...
|
||||||
|
|
||||||
def set_mute(self, on_off: bool = ...) -> 'DriverOptions': ...
|
def set_mute(self, on_off: bool = True) -> 'DriverOptions': ...
|
||||||
|
|
||||||
def set_user_agent(self, user_agent: str) -> 'DriverOptions': ...
|
def set_user_agent(self, user_agent: str) -> 'DriverOptions': ...
|
||||||
|
|
||||||
@ -203,13 +203,13 @@ class DriverOptions(Options):
|
|||||||
def set_page_load_strategy(self, value: str) -> 'DriverOptions': ...
|
def set_page_load_strategy(self, value: str) -> 'DriverOptions': ...
|
||||||
|
|
||||||
def set_paths(self,
|
def set_paths(self,
|
||||||
driver_path: str = ...,
|
driver_path: str = None,
|
||||||
chrome_path: str = ...,
|
chrome_path: str = None,
|
||||||
local_port: Union[int, str] = ...,
|
local_port: Union[int, str] = None,
|
||||||
debugger_address: str = ...,
|
debugger_address: str = None,
|
||||||
download_path: str = ...,
|
download_path: str = None,
|
||||||
user_data_path: str = ...,
|
user_data_path: str = None,
|
||||||
cache_path: str = ...) -> 'DriverOptions': ...
|
cache_path: str = None) -> 'DriverOptions': ...
|
||||||
|
|
||||||
def as_dict(self) -> dict: ...
|
def as_dict(self) -> dict: ...
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
[paths]
|
[paths]
|
||||||
chromedriver_path =
|
chromedriver_path = D:\coding\projects\DrissionPage\DrissionPage\chromedriver.exe
|
||||||
tmp_path =
|
tmp_path =
|
||||||
|
|
||||||
[chrome_options]
|
[chrome_options]
|
||||||
debugger_address = 127.0.0.1:9222
|
debugger_address = 127.0.0.1:9222
|
||||||
binary_location = chrome
|
binary_location = C:\Program Files\Google\Chrome\Application\chrome.exe
|
||||||
arguments = ['--no-first-run', '--no-sandbox', '--disable-gpu', '--ignore-certificate-errors', '--disable-infobars', '--disable-popup-blocking']
|
arguments = ['--no-first-run', '--no-sandbox', '--disable-gpu', '--ignore-certificate-errors', '--disable-infobars', '--disable-popup-blocking']
|
||||||
extensions = []
|
extensions = []
|
||||||
experimental_options = {'prefs': {'profile.default_content_settings.popups': 0, 'profile.default_content_setting_values': {'notifications': 2}, 'plugins.plugins_list': [{'enabled': False, 'name': 'Chrome PDF Viewer'}]}, 'useAutomationExtension': False, 'excludeSwitches': ['enable-automation']}
|
experimental_options = {'prefs': {'profile.default_content_settings.popups': 0, 'profile.default_content_setting_values': {'notifications': 2}, 'plugins.plugins_list': [{'enabled': False, 'name': 'Chrome PDF Viewer'}]}, 'useAutomationExtension': False, 'excludeSwitches': ['enable-automation']}
|
||||||
|
@ -395,10 +395,10 @@ def create_driver(chrome_path, driver_path, options):
|
|||||||
except (WebDriverException, SessionNotCreatedException):
|
except (WebDriverException, SessionNotCreatedException):
|
||||||
print('打开失败,尝试获取driver。\n')
|
print('打开失败,尝试获取driver。\n')
|
||||||
from .easy_set import get_match_driver
|
from .easy_set import get_match_driver
|
||||||
from DrissionPage.easy_set import _get_chrome_path
|
from DrissionPage.easy_set import get_chrome_path
|
||||||
|
|
||||||
if chrome_path == 'chrome':
|
if chrome_path == 'chrome':
|
||||||
chrome_path = _get_chrome_path(show_msg=False, from_ini=False)
|
chrome_path = get_chrome_path(show_msg=False, from_ini=False)
|
||||||
|
|
||||||
if chrome_path:
|
if chrome_path:
|
||||||
driver_path = get_match_driver(chrome_path=chrome_path, check_version=False, show_msg=True)
|
driver_path = get_match_driver(chrome_path=chrome_path, check_version=False, show_msg=True)
|
||||||
|
@ -18,10 +18,10 @@ from .config import SessionOptions, DriverOptions
|
|||||||
class Drission(object):
|
class Drission(object):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
driver_or_options: Union[RemoteWebDriver, Options, DriverOptions, bool] = ...,
|
driver_or_options: Union[RemoteWebDriver, Options, DriverOptions, bool] = None,
|
||||||
session_or_options: Union[Session, dict, SessionOptions, bool] = ...,
|
session_or_options: Union[Session, dict, SessionOptions, bool] = None,
|
||||||
ini_path: str = ...,
|
ini_path: str = None,
|
||||||
proxy: dict = ...):
|
proxy: dict = None):
|
||||||
self._session: Session = ...
|
self._session: Session = ...
|
||||||
self._session_options: dict = ...
|
self._session_options: dict = ...
|
||||||
self._proxy: dict = ...
|
self._proxy: dict = ...
|
||||||
@ -50,7 +50,7 @@ class Drission(object):
|
|||||||
def proxy(self) -> Union[None, dict]: ...
|
def proxy(self) -> Union[None, dict]: ...
|
||||||
|
|
||||||
@proxy.setter
|
@proxy.setter
|
||||||
def proxy(self, proxies: dict = ...) -> None: ...
|
def proxy(self, proxies: dict = None) -> None: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def debugger_progress(self): ...
|
def debugger_progress(self): ...
|
||||||
@ -63,12 +63,12 @@ class Drission(object):
|
|||||||
|
|
||||||
def show_browser(self) -> None: ...
|
def show_browser(self) -> None: ...
|
||||||
|
|
||||||
def _show_or_hide_browser(self, hide: bool = ...) -> None: ...
|
def _show_or_hide_browser(self, hide: bool = True) -> None: ...
|
||||||
|
|
||||||
def set_cookies(self,
|
def set_cookies(self,
|
||||||
cookies: Union[RequestsCookieJar, list, tuple, str, dict],
|
cookies: Union[RequestsCookieJar, list, tuple, str, dict],
|
||||||
set_session: bool = ...,
|
set_session: bool = False,
|
||||||
set_driver: bool = ...) -> None: ...
|
set_driver: bool = False) -> None: ...
|
||||||
|
|
||||||
def _set_session(self, data: dict) -> None: ...
|
def _set_session(self, data: dict) -> None: ...
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ class Drission(object):
|
|||||||
|
|
||||||
def cookies_to_driver(self, url: str) -> None: ...
|
def cookies_to_driver(self, url: str) -> None: ...
|
||||||
|
|
||||||
def close_driver(self, kill: bool = ...) -> None: ...
|
def close_driver(self, kill: bool = False) -> None: ...
|
||||||
|
|
||||||
def close_session(self) -> None: ...
|
def close_session(self) -> None: ...
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ def user_agent_to_session(driver: RemoteWebDriver, session: Session) -> None: ..
|
|||||||
def create_driver(chrome_path: str, driver_path: str, options: Options) -> WebDriver: ...
|
def create_driver(chrome_path: str, driver_path: str, options: Options) -> WebDriver: ...
|
||||||
|
|
||||||
|
|
||||||
def get_chrome_hwnds_from_pid(pid:str) -> list: ...
|
def get_chrome_hwnds_from_pid(pid: str) -> list: ...
|
||||||
|
|
||||||
|
|
||||||
def kill_progress(pid: str = ..., port: int = ...) -> bool: ...
|
def kill_progress(pid: str = None, port: int = None) -> bool: ...
|
||||||
|
@ -133,7 +133,7 @@ class DriverElement(DrissionElement):
|
|||||||
"""
|
"""
|
||||||
return make_session_ele(self, loc_or_str)
|
return make_session_ele(self, loc_or_str)
|
||||||
|
|
||||||
def s_eles(self, loc_or_str=None):
|
def s_eles(self, loc_or_str):
|
||||||
"""查找所有符合条件的元素以SessionElement列表形式返回 \n
|
"""查找所有符合条件的元素以SessionElement列表形式返回 \n
|
||||||
:param loc_or_str: 定位符
|
:param loc_or_str: 定位符
|
||||||
:return: SessionElement或属性、文本组成的列表
|
:return: SessionElement或属性、文本组成的列表
|
||||||
@ -1136,7 +1136,7 @@ class ElementWaiter(object):
|
|||||||
return self._wait_ele('hidden')
|
return self._wait_ele('hidden')
|
||||||
|
|
||||||
def _wait_ele(self, mode):
|
def _wait_ele(self, mode):
|
||||||
"""执行等待
|
"""执行等待 \n
|
||||||
:param mode: 等待模式
|
:param mode: 等待模式
|
||||||
:return: 是否等待成功
|
:return: 是否等待成功
|
||||||
"""
|
"""
|
||||||
|
@ -18,7 +18,7 @@ from .session_element import SessionElement
|
|||||||
|
|
||||||
class DriverElement(DrissionElement):
|
class DriverElement(DrissionElement):
|
||||||
|
|
||||||
def __init__(self, ele: WebElement, page: Union[DriverPage, MixPage] = ...):
|
def __init__(self, ele: WebElement, page: Union[DriverPage, MixPage] = None):
|
||||||
self._inner_ele: WebElement = ...
|
self._inner_ele: WebElement = ...
|
||||||
self._select: Select = ...
|
self._select: Select = ...
|
||||||
self._scroll: Scroll = ...
|
self._scroll: Scroll = ...
|
||||||
@ -28,7 +28,7 @@ class DriverElement(DrissionElement):
|
|||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union['DriverElement', str, None]: ...
|
timeout: float = None) -> Union['DriverElement', str, None]: ...
|
||||||
|
|
||||||
# -----------------共有属性和方法-------------------
|
# -----------------共有属性和方法-------------------
|
||||||
@property
|
@property
|
||||||
@ -56,21 +56,21 @@ class DriverElement(DrissionElement):
|
|||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union['DriverElement', str, None]: ...
|
timeout: float = None) -> Union['DriverElement', str, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union['DriverElement', str]]: ...
|
timeout: float = None) -> List[Union['DriverElement', str]]: ...
|
||||||
|
|
||||||
def s_ele(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> Union[SessionElement, str, None]: ...
|
def s_ele(self, loc_or_str: Union[Tuple[str, str], str] = None) -> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...,
|
timeout: float = None,
|
||||||
single: bool = ...,
|
single: bool = True,
|
||||||
relative: bool = ...) -> Union['DriverElement', str, None, List[Union['DriverElement', str]]]: ...
|
relative: bool = False) -> Union['DriverElement', str, None, List[Union['DriverElement', str]]]: ...
|
||||||
|
|
||||||
def _get_ele_path(self, mode) -> str: ...
|
def _get_ele_path(self, mode) -> str: ...
|
||||||
|
|
||||||
@ -99,92 +99,92 @@ class DriverElement(DrissionElement):
|
|||||||
@property
|
@property
|
||||||
def scroll(self) -> Scroll: ...
|
def scroll(self) -> Scroll: ...
|
||||||
|
|
||||||
def parent(self, level_or_loc: Union[tuple, str, int] = ...) -> Union['DriverElement', None]: ...
|
def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union['DriverElement', None]: ...
|
||||||
|
|
||||||
def prev(self,
|
def prev(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> Union['DriverElement', str, None]: ...
|
timeout: float = 0) -> Union['DriverElement', str, None]: ...
|
||||||
|
|
||||||
def next(self,
|
def next(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> Union['DriverElement', str, None]: ...
|
timeout: float = 0) -> Union['DriverElement', str, None]: ...
|
||||||
|
|
||||||
def before(self,
|
def before(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> Union['DriverElement', str, None]: ...
|
timeout: float = None) -> Union['DriverElement', str, None]: ...
|
||||||
|
|
||||||
def after(self,
|
def after(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> Union['DriverElement', str, None]: ...
|
timeout: float = None) -> Union['DriverElement', str, None]: ...
|
||||||
|
|
||||||
def prevs(self,
|
def prevs(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['DriverElement', str]]: ...
|
timeout: float = 0) -> List[Union['DriverElement', str]]: ...
|
||||||
|
|
||||||
def nexts(self,
|
def nexts(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['DriverElement', str]]: ...
|
timeout: float = 0) -> List[Union['DriverElement', str]]: ...
|
||||||
|
|
||||||
def befores(self,
|
def befores(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['DriverElement', str]]: ...
|
timeout: float = None) -> List[Union['DriverElement', str]]: ...
|
||||||
|
|
||||||
def afters(self,
|
def afters(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['DriverElement', str]]: ...
|
timeout: float = None) -> List[Union['DriverElement', str]]: ...
|
||||||
|
|
||||||
def left(self, index: int = ..., filter_loc: Union[tuple, str] = ...) -> DriverElement: ...
|
def left(self, index: int = 1, filter_loc: Union[tuple, str] = '') -> DriverElement: ...
|
||||||
|
|
||||||
def right(self, index: int = ..., filter_loc: Union[tuple, str] = ...) -> 'DriverElement': ...
|
def right(self, index: int = 1, filter_loc: Union[tuple, str] = '') -> 'DriverElement': ...
|
||||||
|
|
||||||
def above(self, index: int = ..., filter_loc: Union[tuple, str] = ...) -> 'DriverElement': ...
|
def above(self, index: int = 1, filter_loc: Union[tuple, str] = '') -> 'DriverElement': ...
|
||||||
|
|
||||||
def below(self, index: int = ..., filter_loc: Union[tuple, str] = ...) -> 'DriverElement': ...
|
def below(self, index: int = 1, filter_loc: Union[tuple, str] = '') -> 'DriverElement': ...
|
||||||
|
|
||||||
def near(self, index: int = ..., filter_loc: Union[tuple, str] = ...) -> 'DriverElement': ...
|
def near(self, index: int = 1, filter_loc: Union[tuple, str] = '') -> 'DriverElement': ...
|
||||||
|
|
||||||
def lefts(self, filter_loc: Union[tuple, str] = ...) -> List['DriverElement']: ...
|
def lefts(self, filter_loc: Union[tuple, str] = '') -> List['DriverElement']: ...
|
||||||
|
|
||||||
def rights(self, filter_loc: Union[tuple, str] = ...) -> List['DriverElement']: ...
|
def rights(self, filter_loc: Union[tuple, str] = '') -> List['DriverElement']: ...
|
||||||
|
|
||||||
def aboves(self, filter_loc: Union[tuple, str] = ...) -> List['DriverElement']: ...
|
def aboves(self, filter_loc: Union[tuple, str] = '') -> List['DriverElement']: ...
|
||||||
|
|
||||||
def belows(self, filter_loc: Union[tuple, str] = ...) -> List['DriverElement']: ...
|
def belows(self, filter_loc: Union[tuple, str] = '') -> List['DriverElement']: ...
|
||||||
|
|
||||||
def nears(self, filter_loc: Union[tuple, str] = ...) -> List['DriverElement']: ...
|
def nears(self, filter_loc: Union[tuple, str] = '') -> List['DriverElement']: ...
|
||||||
|
|
||||||
def wait_ele(self,
|
def wait_ele(self,
|
||||||
loc_or_ele: Union[str, tuple, DrissionElement, WebElement],
|
loc_or_ele: Union[str, tuple, DrissionElement, WebElement],
|
||||||
timeout: float = ...) -> 'ElementWaiter': ...
|
timeout: float = None) -> 'ElementWaiter': ...
|
||||||
|
|
||||||
def style(self, style: str, pseudo_ele: str = ...) -> str: ...
|
def style(self, style: str, pseudo_ele: str = '') -> str: ...
|
||||||
|
|
||||||
def click(self, by_js: bool = ..., timeout: float = ...) -> bool: ...
|
def click(self, by_js: bool = None, timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def click_at(self,
|
def click_at(self,
|
||||||
x: Union[int, str] = ...,
|
x: Union[int, str] = None,
|
||||||
y: Union[int, str] = ...,
|
y: Union[int, str] = None,
|
||||||
by_js: bool = ...) -> None: ...
|
by_js: bool = False) -> None: ...
|
||||||
|
|
||||||
def r_click(self) -> None: ...
|
def r_click(self) -> None: ...
|
||||||
|
|
||||||
def r_click_at(self, x: Union[int, str] = ..., y: Union[int, str] = ...) -> None: ...
|
def r_click_at(self, x: Union[int, str] = None, y: Union[int, str] = None) -> None: ...
|
||||||
|
|
||||||
def input(self,
|
def input(self,
|
||||||
vals: Union[str, tuple],
|
vals: Union[str, tuple],
|
||||||
clear: bool = ...,
|
clear: bool = True,
|
||||||
insure: bool = ...,
|
insure: bool = True,
|
||||||
timeout: float = ...) -> bool: ...
|
timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def run_script(self, script: str, *args) -> Any: ...
|
def run_script(self, script: str, *args) -> Any: ...
|
||||||
|
|
||||||
def submit(self) -> Union[bool, None]: ...
|
def submit(self) -> Union[bool, None]: ...
|
||||||
|
|
||||||
def clear(self, insure: bool = ...) -> Union[None, bool]: ...
|
def clear(self, insure: bool = True) -> Union[None, bool]: ...
|
||||||
|
|
||||||
def is_selected(self) -> bool: ...
|
def is_selected(self) -> bool: ...
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ class DriverElement(DrissionElement):
|
|||||||
|
|
||||||
def is_valid(self) -> bool: ...
|
def is_valid(self) -> bool: ...
|
||||||
|
|
||||||
def screenshot(self, path: str = ..., filename: str = ..., as_bytes: bool = ...) -> Union[str, bytes]: ...
|
def screenshot(self, path: str = None, filename: str = None, as_bytes: bool = False) -> Union[str, bytes]: ...
|
||||||
|
|
||||||
def prop(self, prop: str) -> str: ...
|
def prop(self, prop: str) -> str: ...
|
||||||
|
|
||||||
@ -204,29 +204,29 @@ class DriverElement(DrissionElement):
|
|||||||
|
|
||||||
def remove_attr(self, attr: str) -> bool: ...
|
def remove_attr(self, attr: str) -> bool: ...
|
||||||
|
|
||||||
def drag(self, x: int, y: int, speed: int = ..., shake: bool = ...) -> None: ...
|
def drag(self, x: int, y: int, speed: int = 40, shake: bool = True) -> None: ...
|
||||||
|
|
||||||
def drag_to(self,
|
def drag_to(self,
|
||||||
ele_or_loc: Union[tuple, WebElement, DrissionElement],
|
ele_or_loc: Union[tuple, WebElement, DrissionElement],
|
||||||
speed: int = ...,
|
speed: int = 40,
|
||||||
shake: bool = ...) -> None: ...
|
shake: bool = True) -> None: ...
|
||||||
|
|
||||||
def hover(self, x: int = ..., y: int = ...) -> None: ...
|
def hover(self, x: int = None, y: int = None) -> None: ...
|
||||||
|
|
||||||
def _get_relative_eles(self,
|
def _get_relative_eles(self,
|
||||||
mode: str,
|
mode: str,
|
||||||
loc: Union[tuple, str] = ...) -> Union[List['DriverElement'], 'DriverElement']: ...
|
loc: Union[tuple, str] = '') -> Union[List['DriverElement'], 'DriverElement']: ...
|
||||||
|
|
||||||
|
|
||||||
def make_driver_ele(page_or_ele: Union[DriverPage, MixPage, DriverElement, ShadowRootElement],
|
def make_driver_ele(page_or_ele: Union[DriverPage, MixPage, DriverElement, ShadowRootElement],
|
||||||
loc: Union[str, Tuple[str, str]],
|
loc: Union[str, Tuple[str, str]],
|
||||||
single: bool = ...,
|
single: bool = True,
|
||||||
timeout: float = ...) -> Union[DriverElement, str, None, List[Union[DriverElement, str]]]: ...
|
timeout: float = None) -> Union[DriverElement, str, None, List[Union[DriverElement, str]]]: ...
|
||||||
|
|
||||||
|
|
||||||
class ElementsByXpath(object):
|
class ElementsByXpath(object):
|
||||||
|
|
||||||
def __init__(self, page, xpath: str = ..., single: bool = ..., timeout: float = ...):
|
def __init__(self, page, xpath: str = None, single: bool = False, timeout: float = 10):
|
||||||
self.single: bool = ...
|
self.single: bool = ...
|
||||||
self.xpath: str = ...
|
self.xpath: str = ...
|
||||||
self.page: Union[MixPage, DriverPage] = ...
|
self.page: Union[MixPage, DriverPage] = ...
|
||||||
@ -241,7 +241,7 @@ class Select(object):
|
|||||||
self.select_ele: SeleniumSelect = ...
|
self.select_ele: SeleniumSelect = ...
|
||||||
self.inner_ele: DriverElement = ...
|
self.inner_ele: DriverElement = ...
|
||||||
|
|
||||||
def __call__(self, text_or_index: Union[str, int, list, tuple], timeout: float = ...) -> bool: ...
|
def __call__(self, text_or_index: Union[str, int, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_multi(self) -> bool: ...
|
def is_multi(self) -> bool: ...
|
||||||
@ -257,26 +257,26 @@ class Select(object):
|
|||||||
|
|
||||||
def clear(self) -> None: ...
|
def clear(self) -> None: ...
|
||||||
|
|
||||||
def select(self, text_or_index: Union[str, int, list, tuple], timeout: float = ...) -> bool: ...
|
def select(self, text_or_index: Union[str, int, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def select_by_value(self, value: Union[str, list, tuple], timeout: float = ...) -> bool: ...
|
def select_by_value(self, value: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def deselect(self, text_or_index: Union[str, int, list, tuple], timeout: float = ...) -> bool: ...
|
def deselect(self, text_or_index: Union[str, int, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def deselect_by_value(self, value: Union[str, list, tuple], timeout: float = ...) -> bool: ...
|
def deselect_by_value(self, value: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def invert(self) -> None: ...
|
def invert(self) -> None: ...
|
||||||
|
|
||||||
def _select(self,
|
def _select(self,
|
||||||
text_value_index: Union[str, int, list, tuple] = ...,
|
text_value_index: Union[str, int, list, tuple] = ...,
|
||||||
para_type: str = ...,
|
para_type: str = 'text',
|
||||||
deselect: bool = ...,
|
deselect: bool = False,
|
||||||
timeout: float = ...) -> bool: ...
|
timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def _select_multi(self,
|
def _select_multi(self,
|
||||||
text_value_index: Union[list, tuple] = ...,
|
text_value_index: Union[list, tuple] = None,
|
||||||
para_type: str = ...,
|
para_type: str = 'text',
|
||||||
deselect: bool = ...) -> bool: ...
|
deselect: bool = False) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
class ElementWaiter(object):
|
class ElementWaiter(object):
|
||||||
@ -284,7 +284,7 @@ class ElementWaiter(object):
|
|||||||
def __init__(self,
|
def __init__(self,
|
||||||
page_or_ele,
|
page_or_ele,
|
||||||
loc_or_ele: Union[str, tuple, DriverElement, WebElement],
|
loc_or_ele: Union[str, tuple, DriverElement, WebElement],
|
||||||
timeout: float = ...):
|
timeout: float = None):
|
||||||
self.target: Union[DriverElement, WebElement, tuple] = ...
|
self.target: Union[DriverElement, WebElement, tuple] = ...
|
||||||
self.timeout: float = ...
|
self.timeout: float = ...
|
||||||
self.driver: Union[WebElement, RemoteWebDriver] = ...
|
self.driver: Union[WebElement, RemoteWebDriver] = ...
|
||||||
@ -317,10 +317,10 @@ class Scroll(object):
|
|||||||
|
|
||||||
def to_location(self, x: int, y: int) -> None: ...
|
def to_location(self, x: int, y: int) -> None: ...
|
||||||
|
|
||||||
def up(self, pixel: int = ...) -> None: ...
|
def up(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
def down(self, pixel: int = ...) -> None: ...
|
def down(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
def left(self, pixel: int = ...) -> None: ...
|
def left(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
def right(self, pixel: int = ...) -> None: ...
|
def right(self, pixel: int = 300) -> None: ...
|
||||||
|
@ -101,7 +101,7 @@ class DriverPage(BasePage):
|
|||||||
else:
|
else:
|
||||||
return make_session_ele(self, loc_or_ele)
|
return make_session_ele(self, loc_or_ele)
|
||||||
|
|
||||||
def s_eles(self, loc_or_str=None):
|
def s_eles(self, loc_or_str):
|
||||||
"""查找所有符合条件的元素以SessionElement列表形式返回 \n
|
"""查找所有符合条件的元素以SessionElement列表形式返回 \n
|
||||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:return: SessionElement对象组成的列表
|
:return: SessionElement对象组成的列表
|
||||||
|
@ -18,14 +18,14 @@ from .session_element import SessionElement
|
|||||||
|
|
||||||
class DriverPage(BasePage):
|
class DriverPage(BasePage):
|
||||||
|
|
||||||
def __init__(self, driver: RemoteWebDriver, timeout: float = ...) -> None:
|
def __init__(self, driver: RemoteWebDriver, timeout: float = 10) -> None:
|
||||||
self._driver: RemoteWebDriver = ...
|
self._driver: RemoteWebDriver = ...
|
||||||
self._url: str = ...
|
self._url: str = ...
|
||||||
self._wait_object: WebDriverWait = ...
|
self._wait_object: WebDriverWait = ...
|
||||||
self._scroll: Scroll = ...
|
self._scroll: Scroll = ...
|
||||||
|
|
||||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str, DriverElement, WebElement],
|
def __call__(self, loc_or_str: Union[Tuple[str, str], str, DriverElement, WebElement],
|
||||||
timeout: float = ...) -> Union[DriverElement, str, None]: ...
|
timeout: float = None) -> Union[DriverElement, str, None]: ...
|
||||||
|
|
||||||
# -----------------共有属性和方法-------------------
|
# -----------------共有属性和方法-------------------
|
||||||
@property
|
@property
|
||||||
@ -39,29 +39,29 @@ class DriverPage(BasePage):
|
|||||||
|
|
||||||
def get(self,
|
def get(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool = ...,
|
show_errmsg: bool = False,
|
||||||
retry: int = ...,
|
retry: int = None,
|
||||||
interval: float = ...) -> Union[None, bool]: ...
|
interval: float = None) -> Union[None, bool]: ...
|
||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, DriverElement, WebElement],
|
loc_or_ele: Union[Tuple[str, str], str, DriverElement, WebElement],
|
||||||
timeout: float = ...) -> Union[DriverElement, str, None]: ...
|
timeout: float = None) -> Union[DriverElement, str, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union[DriverElement, str]]: ...
|
timeout: float = None) -> List[Union[DriverElement, str]]: ...
|
||||||
|
|
||||||
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str, DriverElement] = ...) -> Union[
|
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str, DriverElement] = None) \
|
||||||
SessionElement, str, None]: ...
|
-> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, DriverElement, WebElement],
|
loc_or_ele: Union[Tuple[str, str], str, DriverElement, WebElement],
|
||||||
timeout: float = ...,
|
timeout: float = None,
|
||||||
single: bool = ...) -> Union[DriverElement, str, None, List[Union[DriverElement, str]]]: ...
|
single: bool = True) -> Union[DriverElement, str, None, List[Union[DriverElement, str]]]: ...
|
||||||
|
|
||||||
def get_cookies(self, as_dict: bool = ...) -> Union[list, dict]: ...
|
def get_cookies(self, as_dict: bool = False) -> Union[list, dict]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timeout(self) -> float: ...
|
def timeout(self) -> float: ...
|
||||||
@ -71,9 +71,9 @@ class DriverPage(BasePage):
|
|||||||
|
|
||||||
def _d_connect(self,
|
def _d_connect(self,
|
||||||
to_url: str,
|
to_url: str,
|
||||||
times: int = ...,
|
times: int = 0,
|
||||||
interval: float = ...,
|
interval: float = 1,
|
||||||
show_errmsg: bool = ...) -> Union[bool, None]: ...
|
show_errmsg: bool = False) -> Union[bool, None]: ...
|
||||||
|
|
||||||
# ----------------driver独有属性和方法-----------------------
|
# ----------------driver独有属性和方法-----------------------
|
||||||
@property
|
@property
|
||||||
@ -106,11 +106,11 @@ class DriverPage(BasePage):
|
|||||||
@property
|
@property
|
||||||
def to_frame(self) -> ToFrame: ...
|
def to_frame(self) -> ToFrame: ...
|
||||||
|
|
||||||
def set_timeouts(self, implicit: float = ..., pageLoad: float = ..., script: float = ...) -> None: ...
|
def set_timeouts(self, implicit: float = None, pageLoad: float = None, script: float = None) -> None: ...
|
||||||
|
|
||||||
def wait_ele(self,
|
def wait_ele(self,
|
||||||
loc_or_ele: Union[str, tuple, DriverElement, WebElement],
|
loc_or_ele: Union[str, tuple, DriverElement, WebElement],
|
||||||
timeout: float = ...) -> ElementWaiter: ...
|
timeout: float = None) -> ElementWaiter: ...
|
||||||
|
|
||||||
def check_page(self) -> Union[bool, None]: ...
|
def check_page(self) -> Union[bool, None]: ...
|
||||||
|
|
||||||
@ -120,31 +120,31 @@ class DriverPage(BasePage):
|
|||||||
|
|
||||||
def run_cdp(self, cmd: str, **cmd_args) -> Any: ...
|
def run_cdp(self, cmd: str, **cmd_args) -> Any: ...
|
||||||
|
|
||||||
def create_tab(self, url: str = ...) -> None: ...
|
def create_tab(self, url: str = '') -> None: ...
|
||||||
|
|
||||||
def close_tabs(self, num_or_handles: Union[int, str, list, tuple] = ...) -> None: ...
|
def close_tabs(self, num_or_handles: Union[int, str, list, tuple] = None) -> None: ...
|
||||||
|
|
||||||
def close_other_tabs(self, num_or_handles: Union[int, str, list, tuple] = ...) -> None: ...
|
def close_other_tabs(self, num_or_handles: Union[int, str, list, tuple] = None) -> None: ...
|
||||||
|
|
||||||
def to_tab(self, num_or_handle: Union[int, str] = ...) -> None: ...
|
def to_tab(self, num_or_handle: Union[int, str] = 0) -> None: ...
|
||||||
|
|
||||||
def set_ua_to_tab(self, ua: str) -> None: ...
|
def set_ua_to_tab(self, ua: str) -> None: ...
|
||||||
|
|
||||||
def get_session_storage(self, item: str = ...) -> Union[str, dict, None]: ...
|
def get_session_storage(self, item: str = None) -> Union[str, dict, None]: ...
|
||||||
|
|
||||||
def get_local_storage(self, item: str = ...) -> Union[str, dict, None]: ...
|
def get_local_storage(self, item: str = None) -> Union[str, dict, None]: ...
|
||||||
|
|
||||||
def set_session_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
def set_session_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
||||||
|
|
||||||
def set_local_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
def set_local_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
||||||
|
|
||||||
def clean_cache(self,
|
def clean_cache(self,
|
||||||
session_storage: bool = ...,
|
session_storage: bool = True,
|
||||||
local_storage: bool = ...,
|
local_storage: bool = True,
|
||||||
cache: bool = ...,
|
cache: bool = True,
|
||||||
cookies: bool = ...) -> None: ...
|
cookies: bool = True) -> None: ...
|
||||||
|
|
||||||
def screenshot(self, path: str = ..., filename: str = ..., as_bytes: bool = ...) -> Union[str, bytes]: ...
|
def screenshot(self, path: str = None, filename: str = None, as_bytes: bool = False) -> Union[str, bytes]: ...
|
||||||
|
|
||||||
def scroll_to_see(self, loc_or_ele: Union[str, tuple, WebElement, DriverElement]) -> None: ...
|
def scroll_to_see(self, loc_or_ele: Union[str, tuple, WebElement, DriverElement]) -> None: ...
|
||||||
|
|
||||||
@ -156,11 +156,11 @@ class DriverPage(BasePage):
|
|||||||
|
|
||||||
def forward(self) -> None: ...
|
def forward(self) -> None: ...
|
||||||
|
|
||||||
def set_window_size(self, width: int = ..., height: int = ...) -> None: ...
|
def set_window_size(self, width: int = None, height: int = None) -> None: ...
|
||||||
|
|
||||||
def chrome_downloading(self, download_path: str) -> list: ...
|
def chrome_downloading(self, download_path: str) -> list: ...
|
||||||
|
|
||||||
def process_alert(self, ok: bool = ..., send: str = ..., timeout: float = ...) -> Union[str, None]: ...
|
def process_alert(self, ok: bool = True, send: str = None, timeout: float = None) -> Union[str, None]: ...
|
||||||
|
|
||||||
|
|
||||||
class ToFrame(object):
|
class ToFrame(object):
|
||||||
@ -168,11 +168,12 @@ class ToFrame(object):
|
|||||||
def __init__(self, page: DriverPage):
|
def __init__(self, page: DriverPage):
|
||||||
self.page: DriverPage = ...
|
self.page: DriverPage = ...
|
||||||
|
|
||||||
def __call__(self, condition: Union[int, str, tuple, WebElement, DriverElement] = ...)->Union[DriverPage, MixPage]: ...
|
def __call__(self, condition: Union[int, str, tuple, WebElement, DriverElement] = 'main') -> Union[
|
||||||
|
DriverPage, MixPage]: ...
|
||||||
|
|
||||||
def main(self) -> DriverPage: ...
|
def main(self) -> DriverPage: ...
|
||||||
|
|
||||||
def parent(self, level: int = ...) -> DriverPage: ...
|
def parent(self, level: int = 1) -> DriverPage: ...
|
||||||
|
|
||||||
def by_id(self, id_: str) -> DriverPage: ...
|
def by_id(self, id_: str) -> DriverPage: ...
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from .drission import Drission
|
|||||||
from .session_page import SessionPage
|
from .session_page import SessionPage
|
||||||
|
|
||||||
|
|
||||||
def show_settings(ini_path: str = None) -> None:
|
def show_settings(ini_path=None):
|
||||||
"""打印ini文件内容"""
|
"""打印ini文件内容"""
|
||||||
om = OptionsManager(ini_path)
|
om = OptionsManager(ini_path)
|
||||||
print('paths:')
|
print('paths:')
|
||||||
@ -28,16 +28,16 @@ def show_settings(ini_path: str = None) -> None:
|
|||||||
pprint(om.get_option('session_options'))
|
pprint(om.get_option('session_options'))
|
||||||
|
|
||||||
|
|
||||||
def set_paths(driver_path: str = None,
|
def set_paths(driver_path=None,
|
||||||
chrome_path: str = None,
|
chrome_path=None,
|
||||||
local_port: Union[int, str] = None,
|
local_port=None,
|
||||||
debugger_address: str = None,
|
debugger_address=None,
|
||||||
tmp_path: str = None,
|
tmp_path=None,
|
||||||
download_path: str = None,
|
download_path=None,
|
||||||
user_data_path: str = None,
|
user_data_path=None,
|
||||||
cache_path: str = None,
|
cache_path=None,
|
||||||
ini_path: str = None,
|
ini_path=None,
|
||||||
check_version: bool = False) -> None:
|
check_version=False):
|
||||||
"""快捷的路径设置函数 \n
|
"""快捷的路径设置函数 \n
|
||||||
:param driver_path: chromedriver.exe路径
|
:param driver_path: chromedriver.exe路径
|
||||||
:param chrome_path: chrome.exe路径
|
:param chrome_path: chrome.exe路径
|
||||||
@ -88,7 +88,7 @@ def set_paths(driver_path: str = None,
|
|||||||
check_driver_version(format_path(driver_path), format_path(chrome_path))
|
check_driver_version(format_path(driver_path), format_path(chrome_path))
|
||||||
|
|
||||||
|
|
||||||
def set_argument(arg: str, value: Union[bool, str], ini_path: str = None) -> None:
|
def set_argument(arg, value, ini_path=None):
|
||||||
"""设置浏览器配置argument属性 \n
|
"""设置浏览器配置argument属性 \n
|
||||||
:param arg: 属性名
|
:param arg: 属性名
|
||||||
:param value: 属性值,有值的属性传入值,没有的传入bool
|
:param value: 属性值,有值的属性传入值,没有的传入bool
|
||||||
@ -105,7 +105,7 @@ def set_argument(arg: str, value: Union[bool, str], ini_path: str = None) -> Non
|
|||||||
do.save()
|
do.save()
|
||||||
|
|
||||||
|
|
||||||
def set_headless(on_off: bool = True, ini_path: str = None) -> None:
|
def set_headless(on_off=True, ini_path=None):
|
||||||
"""设置是否隐藏浏览器界面 \n
|
"""设置是否隐藏浏览器界面 \n
|
||||||
:param on_off: 开或关
|
:param on_off: 开或关
|
||||||
:param ini_path: 要修改的ini文件路径
|
:param ini_path: 要修改的ini文件路径
|
||||||
@ -115,7 +115,7 @@ def set_headless(on_off: bool = True, ini_path: str = None) -> None:
|
|||||||
set_argument('--headless', on_off, ini_path)
|
set_argument('--headless', on_off, ini_path)
|
||||||
|
|
||||||
|
|
||||||
def set_no_imgs(on_off: bool = True, ini_path: str = None) -> None:
|
def set_no_imgs(on_off=True, ini_path=None):
|
||||||
"""设置是否禁止加载图片 \n
|
"""设置是否禁止加载图片 \n
|
||||||
:param on_off: 开或关
|
:param on_off: 开或关
|
||||||
:param ini_path: 要修改的ini文件路径
|
:param ini_path: 要修改的ini文件路径
|
||||||
@ -125,7 +125,7 @@ def set_no_imgs(on_off: bool = True, ini_path: str = None) -> None:
|
|||||||
set_argument('--blink-settings=imagesEnabled=false', on_off, ini_path)
|
set_argument('--blink-settings=imagesEnabled=false', on_off, ini_path)
|
||||||
|
|
||||||
|
|
||||||
def set_no_js(on_off: bool = True, ini_path: str = None) -> None:
|
def set_no_js(on_off=True, ini_path=None):
|
||||||
"""设置是否禁用js \n
|
"""设置是否禁用js \n
|
||||||
:param on_off: 开或关
|
:param on_off: 开或关
|
||||||
:param ini_path: 要修改的ini文件路径
|
:param ini_path: 要修改的ini文件路径
|
||||||
@ -135,7 +135,7 @@ def set_no_js(on_off: bool = True, ini_path: str = None) -> None:
|
|||||||
set_argument('--disable-javascript', on_off, ini_path)
|
set_argument('--disable-javascript', on_off, ini_path)
|
||||||
|
|
||||||
|
|
||||||
def set_mute(on_off: bool = True, ini_path: str = None) -> None:
|
def set_mute(on_off=True, ini_path=None):
|
||||||
"""设置是否静音 \n
|
"""设置是否静音 \n
|
||||||
:param on_off: 开或关
|
:param on_off: 开或关
|
||||||
:param ini_path: 要修改的ini文件路径
|
:param ini_path: 要修改的ini文件路径
|
||||||
@ -145,7 +145,7 @@ def set_mute(on_off: bool = True, ini_path: str = None) -> None:
|
|||||||
set_argument('--mute-audio', on_off, ini_path)
|
set_argument('--mute-audio', on_off, ini_path)
|
||||||
|
|
||||||
|
|
||||||
def set_user_agent(user_agent: str, ini_path: str = None) -> None:
|
def set_user_agent(user_agent, ini_path=None):
|
||||||
"""设置user agent \n
|
"""设置user agent \n
|
||||||
:param user_agent: user agent文本
|
:param user_agent: user agent文本
|
||||||
:param ini_path: 要修改的ini文件路径
|
:param ini_path: 要修改的ini文件路径
|
||||||
@ -154,7 +154,7 @@ def set_user_agent(user_agent: str, ini_path: str = None) -> None:
|
|||||||
set_argument('user-agent', user_agent, ini_path)
|
set_argument('user-agent', user_agent, ini_path)
|
||||||
|
|
||||||
|
|
||||||
def set_proxy(proxy: str, ini_path: str = None) -> None:
|
def set_proxy(proxy, ini_path=None):
|
||||||
"""设置代理 \n
|
"""设置代理 \n
|
||||||
:param proxy: 代理网址和端口
|
:param proxy: 代理网址和端口
|
||||||
:param ini_path: 要修改的ini文件路径
|
:param ini_path: 要修改的ini文件路径
|
||||||
@ -163,7 +163,7 @@ def set_proxy(proxy: str, ini_path: str = None) -> None:
|
|||||||
set_argument('--proxy-server', proxy, ini_path)
|
set_argument('--proxy-server', proxy, ini_path)
|
||||||
|
|
||||||
|
|
||||||
def check_driver_version(driver_path: str = None, chrome_path: str = None) -> bool:
|
def check_driver_version(driver_path=None, chrome_path=None):
|
||||||
"""检查传入的chrome和chromedriver是否匹配 \n
|
"""检查传入的chrome和chromedriver是否匹配 \n
|
||||||
:param driver_path: chromedriver.exe路径
|
:param driver_path: chromedriver.exe路径
|
||||||
:param chrome_path: chrome.exe路径
|
:param chrome_path: chrome.exe路径
|
||||||
@ -194,11 +194,11 @@ def check_driver_version(driver_path: str = None, chrome_path: str = None) -> bo
|
|||||||
|
|
||||||
|
|
||||||
# -------------------------自动识别chrome版本号并下载对应driver------------------------
|
# -------------------------自动识别chrome版本号并下载对应driver------------------------
|
||||||
def get_match_driver(ini_path: Union[str, None] = 'default',
|
def get_match_driver(ini_path='default',
|
||||||
save_path: str = None,
|
save_path=None,
|
||||||
chrome_path: str = None,
|
chrome_path=None,
|
||||||
show_msg: bool = True,
|
show_msg=True,
|
||||||
check_version: bool = True) -> Union[str, None]:
|
check_version=True):
|
||||||
"""自动识别chrome版本并下载匹配的driver \n
|
"""自动识别chrome版本并下载匹配的driver \n
|
||||||
:param ini_path: 要读取和修改的ini文件路径
|
:param ini_path: 要读取和修改的ini文件路径
|
||||||
:param save_path: chromedriver保存路径
|
:param save_path: chromedriver保存路径
|
||||||
@ -209,7 +209,7 @@ def get_match_driver(ini_path: Union[str, None] = 'default',
|
|||||||
"""
|
"""
|
||||||
save_path = save_path or str(Path(__file__).parent)
|
save_path = save_path or str(Path(__file__).parent)
|
||||||
|
|
||||||
chrome_path = chrome_path or _get_chrome_path(ini_path, show_msg)
|
chrome_path = chrome_path or get_chrome_path(ini_path, show_msg)
|
||||||
chrome_path = Path(chrome_path).absolute() if chrome_path else None
|
chrome_path = Path(chrome_path).absolute() if chrome_path else None
|
||||||
if show_msg:
|
if show_msg:
|
||||||
print('chrome.exe路径', chrome_path)
|
print('chrome.exe路径', chrome_path)
|
||||||
@ -246,13 +246,17 @@ def get_match_driver(ini_path: Union[str, None] = 'default',
|
|||||||
return driver_path
|
return driver_path
|
||||||
|
|
||||||
|
|
||||||
def _get_chrome_path(ini_path: str = None,
|
def get_chrome_path(ini_path=None,
|
||||||
show_msg: bool = True,
|
show_msg=True,
|
||||||
from_ini: bool = True,
|
from_ini=True,
|
||||||
from_regedit: bool = True,
|
from_regedit=True,
|
||||||
from_system_path: bool = True, ) -> Union[str, None]:
|
from_system_path=True):
|
||||||
"""从ini文件或系统变量中获取chrome.exe的路径 \n
|
"""从ini文件或系统变量中获取chrome.exe的路径 \n
|
||||||
:param ini_path: ini文件路径
|
:param ini_path: ini文件路径
|
||||||
|
:param show_msg: 是否打印信息
|
||||||
|
:param from_ini: 是否从ini文件获取
|
||||||
|
:param from_regedit: 是否从注册表获取
|
||||||
|
:param from_system_path: 是否从系统路径获取
|
||||||
:return: chrome.exe路径
|
:return: chrome.exe路径
|
||||||
"""
|
"""
|
||||||
# -----------从ini文件中获取--------------
|
# -----------从ini文件中获取--------------
|
||||||
|
60
DrissionPage/easy_set.pyi
Normal file
60
DrissionPage/easy_set.pyi
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""
|
||||||
|
@Author : g1879
|
||||||
|
@Contact : g1879@qq.com
|
||||||
|
"""
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
|
def show_settings(ini_path: str = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def set_paths(driver_path: str = None,
|
||||||
|
chrome_path: str = None,
|
||||||
|
local_port: Union[int, str] = None,
|
||||||
|
debugger_address: str = None,
|
||||||
|
tmp_path: str = None,
|
||||||
|
download_path: str = None,
|
||||||
|
user_data_path: str = None,
|
||||||
|
cache_path: str = None,
|
||||||
|
ini_path: str = None,
|
||||||
|
check_version: bool = False) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def set_argument(arg: str, value: Union[bool, str], ini_path: str = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def set_headless(on_off: bool = True, ini_path: str = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def set_no_imgs(on_off: bool = True, ini_path: str = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def set_no_js(on_off: bool = True, ini_path: str = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def set_mute(on_off: bool = True, ini_path: str = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def set_user_agent(user_agent: str, ini_path: str = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def set_proxy(proxy: str, ini_path: str = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
def check_driver_version(driver_path: str = None, chrome_path: str = None) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------自动识别chrome版本号并下载对应driver------------------------
|
||||||
|
def get_match_driver(ini_path: Union[str, None] = 'default',
|
||||||
|
save_path: str = None,
|
||||||
|
chrome_path: str = None,
|
||||||
|
show_msg: bool = True,
|
||||||
|
check_version: bool = True) -> Union[str, None]: ...
|
||||||
|
|
||||||
|
|
||||||
|
def get_chrome_path(ini_path: str = None,
|
||||||
|
show_msg: bool = True,
|
||||||
|
from_ini: bool = True,
|
||||||
|
from_regedit: bool = True,
|
||||||
|
from_system_path: bool = True, ) -> Union[str, None]: ...
|
@ -136,7 +136,7 @@ class MixPage(SessionPage, DriverPage, BasePage):
|
|||||||
elif self._mode == 'd':
|
elif self._mode == 'd':
|
||||||
return super(SessionPage, self).s_ele(loc_or_ele)
|
return super(SessionPage, self).s_ele(loc_or_ele)
|
||||||
|
|
||||||
def s_eles(self, loc_or_str=None):
|
def s_eles(self, loc_or_str):
|
||||||
"""查找所有符合条件的元素以SessionElement形式返回,d模式处理复杂页面时效率很高 \n
|
"""查找所有符合条件的元素以SessionElement形式返回,d模式处理复杂页面时效率很高 \n
|
||||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:return: SessionElement对象或属性、文本组成的列表
|
:return: SessionElement对象或属性、文本组成的列表
|
||||||
|
@ -24,17 +24,17 @@ from .session_page import SessionPage
|
|||||||
class MixPage(SessionPage, DriverPage, BasePage):
|
class MixPage(SessionPage, DriverPage, BasePage):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
mode: str = ...,
|
mode: str = 'd',
|
||||||
drission: Union[Drission, str] = ...,
|
drission: Union[Drission, str] = None,
|
||||||
timeout: float = ...,
|
timeout: float = None,
|
||||||
driver_options: Union[Options, DriverOptions, bool] = ...,
|
driver_options: Union[Options, DriverOptions, bool] = None,
|
||||||
session_options: Union[dict, SessionOptions, bool] = ...) -> None:
|
session_options: Union[dict, SessionOptions, bool] = None) -> None:
|
||||||
self._mode: str = ...
|
self._mode: str = ...
|
||||||
self._drission: Drission = ...
|
self._drission: Drission = ...
|
||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str, DriverElement, SessionElement, WebElement],
|
loc_or_str: Union[Tuple[str, str], str, DriverElement, SessionElement, WebElement],
|
||||||
timeout: float = ...) -> Union[DriverElement, SessionElement, str, None]: ...
|
timeout: float = None) -> Union[DriverElement, SessionElement, str, None]: ...
|
||||||
|
|
||||||
# -----------------共有属性和方法-------------------
|
# -----------------共有属性和方法-------------------
|
||||||
@property
|
@property
|
||||||
@ -51,9 +51,9 @@ class MixPage(SessionPage, DriverPage, BasePage):
|
|||||||
|
|
||||||
def get(self,
|
def get(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool | None = ...,
|
show_errmsg: bool | None = False,
|
||||||
retry: int | None = ...,
|
retry: int | None = None,
|
||||||
interval: float | None = ...,
|
interval: float | None = None,
|
||||||
timeout: float | None = ...,
|
timeout: float | None = ...,
|
||||||
params: dict | None = ...,
|
params: dict | None = ...,
|
||||||
data: Union[dict, str, None] = ...,
|
data: Union[dict, str, None] = ...,
|
||||||
@ -71,24 +71,24 @@ class MixPage(SessionPage, DriverPage, BasePage):
|
|||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, DriverElement, SessionElement, WebElement],
|
loc_or_ele: Union[Tuple[str, str], str, DriverElement, SessionElement, WebElement],
|
||||||
timeout: float = ...) -> Union[DriverElement, SessionElement, str, None]: ...
|
timeout: float = None) -> Union[DriverElement, SessionElement, str, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union[DriverElement, SessionElement, str]]: ...
|
timeout: float = None) -> List[Union[DriverElement, SessionElement, str]]: ...
|
||||||
|
|
||||||
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str, DriverElement, SessionElement] = ...) \
|
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str, DriverElement, SessionElement] = None) \
|
||||||
-> Union[SessionElement, str, None]: ...
|
-> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, DriverElement, SessionElement, WebElement],
|
loc_or_ele: Union[Tuple[str, str], str, DriverElement, SessionElement, WebElement],
|
||||||
timeout: float = ..., single: bool = ...) \
|
timeout: float = None, single: bool = False) \
|
||||||
-> Union[DriverElement, SessionElement, str, None, List[Union[SessionElement, str]], List[
|
-> Union[DriverElement, SessionElement, str, None, List[Union[SessionElement, str]], List[
|
||||||
Union[DriverElement, str]]]: ...
|
Union[DriverElement, str]]]: ...
|
||||||
|
|
||||||
def get_cookies(self, as_dict: bool = ..., all_domains: bool = ...) -> Union[dict, list]: ...
|
def get_cookies(self, as_dict: bool = False, all_domains: bool = False) -> Union[dict, list]: ...
|
||||||
|
|
||||||
# ----------------MixPage独有属性和方法-----------------------
|
# ----------------MixPage独有属性和方法-----------------------
|
||||||
@property
|
@property
|
||||||
@ -109,15 +109,15 @@ class MixPage(SessionPage, DriverPage, BasePage):
|
|||||||
@property
|
@property
|
||||||
def _session_url(self) -> str: ...
|
def _session_url(self) -> str: ...
|
||||||
|
|
||||||
def change_mode(self, mode: str = ..., go: bool = ..., copy_cookies: bool = ...) -> None: ...
|
def change_mode(self, mode: str = None, go: bool = True, copy_cookies: bool = True) -> None: ...
|
||||||
|
|
||||||
def set_cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict], refresh: bool = ...) -> None: ...
|
def set_cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict], refresh: bool = True) -> None: ...
|
||||||
|
|
||||||
def cookies_to_session(self, copy_user_agent: bool = ...) -> None: ...
|
def cookies_to_session(self, copy_user_agent: bool = False) -> None: ...
|
||||||
|
|
||||||
def cookies_to_driver(self, url: str = ...) -> None: ...
|
def cookies_to_driver(self, url: str = None) -> None: ...
|
||||||
|
|
||||||
def check_page(self, by_requests: bool = ...) -> Union[bool, None]: ...
|
def check_page(self, by_requests: bool = False) -> Union[bool, None]: ...
|
||||||
|
|
||||||
def close_driver(self) -> None: ...
|
def close_driver(self) -> None: ...
|
||||||
|
|
||||||
@ -126,12 +126,12 @@ class MixPage(SessionPage, DriverPage, BasePage):
|
|||||||
# ----------------重写SessionPage的函数-----------------------
|
# ----------------重写SessionPage的函数-----------------------
|
||||||
def post(self,
|
def post(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool | None = ...,
|
data: Union[dict, str, None] = None,
|
||||||
retry: int | None = ...,
|
show_errmsg: bool = False,
|
||||||
interval: float | None = ...,
|
retry: int | None = None,
|
||||||
|
interval: float | None = None,
|
||||||
timeout: float | None = ...,
|
timeout: float | None = ...,
|
||||||
params: dict | None = ...,
|
params: dict | None = ...,
|
||||||
data: Union[dict, str, None] = ...,
|
|
||||||
json: Union[dict, str, None] = ...,
|
json: Union[dict, str, None] = ...,
|
||||||
headers: dict | None = ...,
|
headers: dict | None = ...,
|
||||||
cookies: Any | None = ...,
|
cookies: Any | None = ...,
|
||||||
@ -147,7 +147,7 @@ class MixPage(SessionPage, DriverPage, BasePage):
|
|||||||
@property
|
@property
|
||||||
def download(self) -> DownloadKit: ...
|
def download(self) -> DownloadKit: ...
|
||||||
|
|
||||||
def chrome_downloading(self, path: str = ...) -> list: ...
|
def chrome_downloading(self, path: str = None) -> list: ...
|
||||||
|
|
||||||
# ----------------MixPage独有函数-----------------------
|
# ----------------MixPage独有函数-----------------------
|
||||||
def hide_browser(self) -> None: ...
|
def hide_browser(self) -> None: ...
|
||||||
|
@ -80,37 +80,37 @@ class SessionElement(DrissionElement):
|
|||||||
"""
|
"""
|
||||||
return super().parent(level_or_loc)
|
return super().parent(level_or_loc)
|
||||||
|
|
||||||
def prev(self, index=1, filter_loc='', timeout=0):
|
def prev(self, filter_loc='', index=1, timeout=0):
|
||||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n
|
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n
|
||||||
:param index: 前面第几个查询结果元素
|
|
||||||
:param filter_loc: 用于筛选元素的查询语法
|
:param filter_loc: 用于筛选元素的查询语法
|
||||||
|
:param index: 前面第几个查询结果元素
|
||||||
:param timeout: 查找元素的超时时间
|
:param timeout: 查找元素的超时时间
|
||||||
:return: 兄弟元素
|
:return: 兄弟元素
|
||||||
"""
|
"""
|
||||||
return super().prev(index, filter_loc, timeout)
|
return super().prev(index, filter_loc, timeout)
|
||||||
|
|
||||||
def next(self, index=1, filter_loc='', timeout=0):
|
def next(self, filter_loc='', index=1, timeout=0):
|
||||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n
|
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n
|
||||||
:param index: 后面第几个查询结果元素
|
|
||||||
:param filter_loc: 用于筛选元素的查询语法
|
:param filter_loc: 用于筛选元素的查询语法
|
||||||
|
:param index: 后面第几个查询结果元素
|
||||||
:param timeout: 查找元素的超时时间
|
:param timeout: 查找元素的超时时间
|
||||||
:return: 兄弟元素
|
:return: 兄弟元素
|
||||||
"""
|
"""
|
||||||
return super().next(index, filter_loc, timeout)
|
return super().next(index, filter_loc, timeout)
|
||||||
|
|
||||||
def before(self, index=1, filter_loc='', timeout=None):
|
def before(self, filter_loc='', index=1, timeout=None):
|
||||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n
|
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n
|
||||||
:param index: 前面第几个查询结果元素
|
|
||||||
:param filter_loc: 用于筛选元素的查询语法
|
:param filter_loc: 用于筛选元素的查询语法
|
||||||
|
:param index: 前面第几个查询结果元素
|
||||||
:param timeout: 查找元素的超时时间
|
:param timeout: 查找元素的超时时间
|
||||||
:return: 本元素前面的某个元素或节点
|
:return: 本元素前面的某个元素或节点
|
||||||
"""
|
"""
|
||||||
return super().before(index, filter_loc, timeout)
|
return super().before(index, filter_loc, timeout)
|
||||||
|
|
||||||
def after(self, index=1, filter_loc='', timeout=None):
|
def after(self, filter_loc='', index=1, timeout=None):
|
||||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n
|
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n
|
||||||
:param index: 后面第几个查询结果元素
|
|
||||||
:param filter_loc: 用于筛选元素的查询语法
|
:param filter_loc: 用于筛选元素的查询语法
|
||||||
|
:param index: 后面第几个查询结果元素
|
||||||
:param timeout: 查找元素的超时时间
|
:param timeout: 查找元素的超时时间
|
||||||
:return: 本元素后面的某个元素或节点
|
:return: 本元素后面的某个元素或节点
|
||||||
"""
|
"""
|
||||||
@ -204,7 +204,7 @@ class SessionElement(DrissionElement):
|
|||||||
"""
|
"""
|
||||||
return self._ele(loc_or_str)
|
return self._ele(loc_or_str)
|
||||||
|
|
||||||
def s_eles(self, loc_or_str=None):
|
def s_eles(self, loc_or_str):
|
||||||
"""返回当前元素下级所有符合条件的子元素、属性或节点文本 \n
|
"""返回当前元素下级所有符合条件的子元素、属性或节点文本 \n
|
||||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:return: SessionElement对象或属性、文本组成的列表
|
:return: SessionElement对象或属性、文本组成的列表
|
||||||
|
@ -7,6 +7,7 @@ from typing import Union, List, Tuple
|
|||||||
|
|
||||||
from lxml.html import HtmlElement
|
from lxml.html import HtmlElement
|
||||||
|
|
||||||
|
from .driver_page import DriverPage
|
||||||
from .base import DrissionElement, BaseElement
|
from .base import DrissionElement, BaseElement
|
||||||
from .chromium_base import ChromiumBase
|
from .chromium_base import ChromiumBase
|
||||||
from .chromium_element import ChromiumElement
|
from .chromium_element import ChromiumElement
|
||||||
@ -17,7 +18,7 @@ from .session_page import SessionPage
|
|||||||
|
|
||||||
class SessionElement(DrissionElement):
|
class SessionElement(DrissionElement):
|
||||||
|
|
||||||
def __init__(self, ele: HtmlElement, page: Union[SessionPage, None] = ...):
|
def __init__(self, ele: HtmlElement, page: Union[SessionPage, None] = None):
|
||||||
self._inner_ele: HtmlElement = ...
|
self._inner_ele: HtmlElement = ...
|
||||||
self.page: SessionPage = ...
|
self.page: SessionPage = ...
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ class SessionElement(DrissionElement):
|
|||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union['SessionElement', str, None]: ...
|
timeout: float = None) -> Union['SessionElement', str, None]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tag(self) -> str: ...
|
def tag(self) -> str: ...
|
||||||
@ -48,70 +49,70 @@ class SessionElement(DrissionElement):
|
|||||||
@property
|
@property
|
||||||
def raw_text(self) -> str: ...
|
def raw_text(self) -> str: ...
|
||||||
|
|
||||||
def parent(self, level_or_loc: Union[tuple, str, int] = ...) -> Union['SessionElement', None]: ...
|
def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union['SessionElement', None]: ...
|
||||||
|
|
||||||
def prev(self,
|
def prev(self,
|
||||||
index: int = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
filter_loc: Union[tuple, str] = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union['SessionElement', str, None]: ...
|
timeout: float = 0) -> Union['SessionElement', str, None]: ...
|
||||||
|
|
||||||
def next(self,
|
def next(self,
|
||||||
index: int = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
filter_loc: Union[tuple, str] = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union['SessionElement', str, None]: ...
|
timeout: float = 0) -> Union['SessionElement', str, None]: ...
|
||||||
|
|
||||||
def before(self,
|
def before(self,
|
||||||
index: int = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
filter_loc: Union[tuple, str] = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union['SessionElement', str, None]: ...
|
timeout: float = None) -> Union['SessionElement', str, None]: ...
|
||||||
|
|
||||||
def after(self,
|
def after(self,
|
||||||
index: int = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
filter_loc: Union[tuple, str] = ...,
|
index: int = 1,
|
||||||
timeout: float = ...) -> Union['SessionElement', str, None]: ...
|
timeout: float = None) -> Union['SessionElement', str, None]: ...
|
||||||
|
|
||||||
def prevs(self,
|
def prevs(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['SessionElement', str]]: ...
|
timeout: float = 0) -> List[Union['SessionElement', str]]: ...
|
||||||
|
|
||||||
def nexts(self,
|
def nexts(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['SessionElement', str]]: ...
|
timeout: float = 0) -> List[Union['SessionElement', str]]: ...
|
||||||
|
|
||||||
def befores(self,
|
def befores(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['SessionElement', str]]: ...
|
timeout: float = None) -> List[Union['SessionElement', str]]: ...
|
||||||
|
|
||||||
def afters(self,
|
def afters(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = '',
|
||||||
timeout: float = ...) -> List[Union['SessionElement', str]]: ...
|
timeout: float = None) -> List[Union['SessionElement', str]]: ...
|
||||||
|
|
||||||
def attr(self, attr: str) -> Union[str, None]: ...
|
def attr(self, attr: str) -> Union[str, None]: ...
|
||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union['SessionElement', str, None]: ...
|
timeout: float = None) -> Union['SessionElement', str, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union['SessionElement', str]]: ...
|
timeout: float = None) -> List[Union['SessionElement', str]]: ...
|
||||||
|
|
||||||
def s_ele(self,
|
def s_ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str] = ...) -> Union['SessionElement', str, None]: ...
|
loc_or_str: Union[Tuple[str, str], str] = None) -> Union['SessionElement', str, None]: ...
|
||||||
|
|
||||||
def s_eles(self,
|
def s_eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str] = ...) -> List[Union['SessionElement', str]]: ...
|
loc_or_str: Union[Tuple[str, str], str]) -> List[Union['SessionElement', str]]: ...
|
||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...,
|
timeout: float = None,
|
||||||
single: bool = ...,
|
single: bool = True,
|
||||||
relative: bool = ...) -> Union['SessionElement', str, None, List[Union['SessionElement', str]]]: ...
|
relative: bool = False) -> Union['SessionElement', str, None, List[Union['SessionElement', str]]]: ...
|
||||||
|
|
||||||
def _get_ele_path(self, mode: str) -> str: ...
|
def _get_ele_path(self, mode: str) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
def make_session_ele(html_or_ele: Union[str, SessionElement, SessionPage, ChromiumElement, DriverElement, BaseElement,
|
def make_session_ele(html_or_ele: Union[str, SessionElement, SessionPage, ChromiumElement, DriverElement, BaseElement,
|
||||||
ChromiumFrame, ChromiumBase],
|
ChromiumFrame, ChromiumBase, DriverPage],
|
||||||
loc: Union[str, Tuple[str, str]] = ...,
|
loc: Union[str, Tuple[str, str]] = None,
|
||||||
single: bool = ...) -> Union[SessionElement, str, None, List[Union[SessionElement, str]]]: ...
|
single: bool = True) -> Union[SessionElement, str, None, List[Union[SessionElement, str]]]: ...
|
||||||
|
@ -145,7 +145,7 @@ class SessionPage(BasePage):
|
|||||||
"""
|
"""
|
||||||
return make_session_ele(self.html) if loc_or_ele is None else self._ele(loc_or_ele)
|
return make_session_ele(self.html) if loc_or_ele is None else self._ele(loc_or_ele)
|
||||||
|
|
||||||
def s_eles(self, loc_or_str=None):
|
def s_eles(self, loc_or_str):
|
||||||
"""返回页面中符合条件的所有元素、属性或节点文本 \n
|
"""返回页面中符合条件的所有元素、属性或节点文本 \n
|
||||||
:param loc_or_str: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
:param loc_or_str: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
||||||
:return: SessionElement对象或属性、文本
|
:return: SessionElement对象或属性、文本
|
||||||
@ -318,7 +318,7 @@ def set_charset(response) -> Response:
|
|||||||
"""设置Response对象的编码"""
|
"""设置Response对象的编码"""
|
||||||
# 在headers中获取编码
|
# 在headers中获取编码
|
||||||
content_type = response.headers.get('content-type', '').lower()
|
content_type = response.headers.get('content-type', '').lower()
|
||||||
charset = search(r'charset[=: ]*(.*)?[;]', content_type)
|
charset = search(r'charset[=: ]*(.*)?;', content_type)
|
||||||
|
|
||||||
if charset:
|
if charset:
|
||||||
response.encoding = charset.group(1)
|
response.encoding = charset.group(1)
|
||||||
|
@ -17,8 +17,8 @@ from .config import SessionOptions
|
|||||||
|
|
||||||
class SessionPage(BasePage):
|
class SessionPage(BasePage):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
session_or_options: Union[Session, SessionOptions] = ...,
|
session_or_options: Union[Session, SessionOptions] = None,
|
||||||
timeout: float = ...):
|
timeout: float = 10):
|
||||||
self._session: Session = ...
|
self._session: Session = ...
|
||||||
self._url: str = ...
|
self._url: str = ...
|
||||||
self._response: Response = ...
|
self._response: Response = ...
|
||||||
@ -38,7 +38,7 @@ class SessionPage(BasePage):
|
|||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str, SessionElement],
|
loc_or_str: Union[Tuple[str, str], str, SessionElement],
|
||||||
timeout: float = ...) -> Union[SessionElement, str, None]: ...
|
timeout: float = None) -> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
# -----------------共有属性和方法-------------------
|
# -----------------共有属性和方法-------------------
|
||||||
|
|
||||||
@ -53,10 +53,10 @@ class SessionPage(BasePage):
|
|||||||
|
|
||||||
def get(self,
|
def get(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool | None = ...,
|
show_errmsg: bool | None = False,
|
||||||
retry: int | None = ...,
|
retry: int | None = None,
|
||||||
interval: float | None = ...,
|
interval: float | None = None,
|
||||||
timeout: float | None = ...,
|
timeout: float | None = None,
|
||||||
params: dict | None = ...,
|
params: dict | None = ...,
|
||||||
data: Union[dict, str, None] = ...,
|
data: Union[dict, str, None] = ...,
|
||||||
json: Union[dict, str, None] = ...,
|
json: Union[dict, str, None] = ...,
|
||||||
@ -73,25 +73,25 @@ class SessionPage(BasePage):
|
|||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, SessionElement],
|
loc_or_ele: Union[Tuple[str, str], str, SessionElement],
|
||||||
timeout: float = ...) -> Union[SessionElement, str, None]: ...
|
timeout: float = None) -> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union[SessionElement, str]]: ...
|
timeout: float = None) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def s_ele(self,
|
def s_ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, SessionElement] = ...) -> Union[SessionElement, str, None]: ...
|
loc_or_ele: Union[Tuple[str, str], str, SessionElement] = None) -> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, SessionElement],
|
loc_or_ele: Union[Tuple[str, str], str, SessionElement],
|
||||||
timeout: float = ...,
|
timeout: float = None,
|
||||||
single: bool = ...) -> Union[SessionElement, str, None, List[Union[SessionElement, str]]]: ...
|
single: bool = True) -> Union[SessionElement, str, None, List[Union[SessionElement, str]]]: ...
|
||||||
|
|
||||||
def get_cookies(self,
|
def get_cookies(self,
|
||||||
as_dict: bool = ...,
|
as_dict: bool = False,
|
||||||
all_domains: bool = ...) -> Union[dict, list]: ...
|
all_domains: bool = False) -> Union[dict, list]: ...
|
||||||
|
|
||||||
# ----------------session独有属性和方法-----------------------
|
# ----------------session独有属性和方法-----------------------
|
||||||
@property
|
@property
|
||||||
@ -105,12 +105,12 @@ class SessionPage(BasePage):
|
|||||||
|
|
||||||
def post(self,
|
def post(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool | None = ...,
|
data: Union[dict, str, None] = ...,
|
||||||
retry: int | None = ...,
|
show_errmsg: bool = False,
|
||||||
interval: float | None = ...,
|
retry: int | None = None,
|
||||||
|
interval: float | None = None,
|
||||||
timeout: float | None = ...,
|
timeout: float | None = ...,
|
||||||
params: dict | None = ...,
|
params: dict | None = ...,
|
||||||
data: Union[dict, str, None] = ...,
|
|
||||||
json: Union[dict, str, None] = ...,
|
json: Union[dict, str, None] = ...,
|
||||||
headers: dict | None = ...,
|
headers: dict | None = ...,
|
||||||
cookies: Any | None = ...,
|
cookies: Any | None = ...,
|
||||||
@ -126,19 +126,19 @@ class SessionPage(BasePage):
|
|||||||
def _s_connect(self,
|
def _s_connect(self,
|
||||||
url: str,
|
url: str,
|
||||||
mode: str,
|
mode: str,
|
||||||
data: Union[dict, str, None] = ...,
|
data: Union[dict, str, None] = None,
|
||||||
show_errmsg: bool = ...,
|
show_errmsg: bool = False,
|
||||||
retry: int = ...,
|
retry: int = None,
|
||||||
interval: float = ...,
|
interval: float = None,
|
||||||
**kwargs) -> bool: ...
|
**kwargs) -> bool: ...
|
||||||
|
|
||||||
def _make_response(self,
|
def _make_response(self,
|
||||||
url: str,
|
url: str,
|
||||||
mode: str = ...,
|
mode: str = 'get',
|
||||||
data: Union[dict, str] = ...,
|
data: Union[dict, str] = None,
|
||||||
retry: int = ...,
|
retry: int = None,
|
||||||
interval: float = ...,
|
interval: float = None,
|
||||||
show_errmsg: bool = ...,
|
show_errmsg: bool = False,
|
||||||
**kwargs) -> tuple: ...
|
**kwargs) -> tuple: ...
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class ShadowRootElement(BaseElement):
|
|||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union[DriverElement, str, None]: ...
|
timeout: float = None) -> Union[DriverElement, str, None]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tag(self) -> str: ...
|
def tag(self) -> str: ...
|
||||||
@ -39,34 +39,35 @@ class ShadowRootElement(BaseElement):
|
|||||||
@property
|
@property
|
||||||
def inner_html(self) -> str: ...
|
def inner_html(self) -> str: ...
|
||||||
|
|
||||||
def parent(self, level_or_loc: Union[str, int] = ...) -> DriverElement: ...
|
def parent(self, level_or_loc: Union[str, int] = 1) -> DriverElement: ...
|
||||||
|
|
||||||
def next(self,
|
def next(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...) -> Union[DriverElement, str, None]: ...
|
filter_loc: Union[tuple, str] = '') -> Union[DriverElement, str, None]: ...
|
||||||
|
|
||||||
def before(self,
|
def before(self,
|
||||||
index: int = ...,
|
index: int = 1,
|
||||||
filter_loc: Union[tuple, str] = ...) -> Union[DriverElement, str, None]: ...
|
filter_loc: Union[tuple, str] = '') -> Union[DriverElement, str, None]: ...
|
||||||
|
|
||||||
def after(self, index: int = ...,
|
def after(self,
|
||||||
filter_loc: Union[tuple, str] = ...) -> Union[DriverElement, str, None]: ...
|
index: int = 1,
|
||||||
|
filter_loc: Union[tuple, str] = '') -> Union[DriverElement, str, None]: ...
|
||||||
|
|
||||||
def nexts(self, filter_loc: Union[tuple, str] = ...) -> List[Union[DriverElement, str]]: ...
|
def nexts(self, filter_loc: Union[tuple, str] = '') -> List[Union[DriverElement, str]]: ...
|
||||||
|
|
||||||
def befores(self, filter_loc: Union[tuple, str] = ...) -> List[Union[DriverElement, str]]: ...
|
def befores(self, filter_loc: Union[tuple, str] = '') -> List[Union[DriverElement, str]]: ...
|
||||||
|
|
||||||
def afters(self, filter_loc: Union[tuple, str] = ...) -> List[Union[DriverElement, str]]: ...
|
def afters(self, filter_loc: Union[tuple, str] = '') -> List[Union[DriverElement, str]]: ...
|
||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> Union[DriverElement, str, None]: ...
|
timeout: float = None) -> Union[DriverElement, str, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union[DriverElement, str]]: ...
|
timeout: float = None) -> List[Union[DriverElement, str]]: ...
|
||||||
|
|
||||||
def s_ele(self, loc_or_str: Union[Tuple[str, str], str]=...) -> Union[SessionElement, str, None]: ...
|
def s_ele(self, loc_or_str: Union[Tuple[str, str], str] = None) -> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
elif self._mode == 'd':
|
elif self._mode == 'd':
|
||||||
return super(SessionPage, self).s_ele(loc_or_ele)
|
return super(SessionPage, self).s_ele(loc_or_ele)
|
||||||
|
|
||||||
def s_eles(self, loc_or_str=None):
|
def s_eles(self, loc_or_str):
|
||||||
"""查找所有符合条件的元素以SessionElement形式返回,d模式处理复杂页面时效率很高 \n
|
"""查找所有符合条件的元素以SessionElement形式返回,d模式处理复杂页面时效率很高 \n
|
||||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:return: SessionElement对象或属性、文本组成的列表
|
:return: SessionElement对象或属性、文本组成的列表
|
||||||
@ -315,21 +315,6 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
if self._has_driver:
|
if self._has_driver:
|
||||||
super(SessionPage, self).set_headers(headers)
|
super(SessionPage, self).set_headers(headers)
|
||||||
|
|
||||||
def check_page(self, by_requests=False):
|
|
||||||
"""d模式时检查网页是否符合预期 \n
|
|
||||||
默认由response状态检查,可重载实现针对性检查 \n
|
|
||||||
:param by_requests: 是否用内置response检查
|
|
||||||
:return: bool或None,None代表不知道结果
|
|
||||||
"""
|
|
||||||
if self._session_url and self._session_url == self.url:
|
|
||||||
return self._response.ok
|
|
||||||
|
|
||||||
# 使用requests访问url并判断可用性
|
|
||||||
if by_requests:
|
|
||||||
self.cookies_to_session()
|
|
||||||
r = self._make_response(self.url, retry=0)[0]
|
|
||||||
return r.ok if r else False
|
|
||||||
|
|
||||||
def close_driver(self):
|
def close_driver(self):
|
||||||
"""关闭driver及浏览器"""
|
"""关闭driver及浏览器"""
|
||||||
if self._has_driver:
|
if self._has_driver:
|
||||||
|
@ -21,11 +21,11 @@ from .chromium_driver import ChromiumDriver
|
|||||||
class WebPage(SessionPage, ChromiumPage, BasePage):
|
class WebPage(SessionPage, ChromiumPage, BasePage):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
mode: str = ...,
|
mode: str = 'd',
|
||||||
timeout: float = ...,
|
timeout: float = 10,
|
||||||
tab_id: str = ...,
|
tab_id: str = None,
|
||||||
driver_or_options: Union[ChromiumDriver, DriverOptions, bool] = ...,
|
driver_or_options: Union[ChromiumDriver, DriverOptions, bool] = None,
|
||||||
session_or_options: Union[Session, SessionOptions, bool] = ...) -> None:
|
session_or_options: Union[Session, SessionOptions, bool] = None) -> None:
|
||||||
self._mode: str = ...
|
self._mode: str = ...
|
||||||
self._has_driver: bool = ...
|
self._has_driver: bool = ...
|
||||||
self._has_session: bool = ...
|
self._has_session: bool = ...
|
||||||
@ -35,7 +35,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str, ChromiumElement, SessionElement],
|
loc_or_str: Union[Tuple[str, str], str, ChromiumElement, SessionElement],
|
||||||
timeout: float = ...) -> Union[ChromiumElement, SessionElement, ChromiumFrame, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, SessionElement, ChromiumFrame, None]: ...
|
||||||
|
|
||||||
# -----------------共有属性和方法-------------------
|
# -----------------共有属性和方法-------------------
|
||||||
@property
|
@property
|
||||||
@ -76,10 +76,10 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
|
|
||||||
def get(self,
|
def get(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool | None = ...,
|
show_errmsg: bool = False,
|
||||||
retry: int | None = ...,
|
retry: int | None = None,
|
||||||
interval: float | None = ...,
|
interval: float | None = None,
|
||||||
timeout: float | None = ...,
|
timeout: float | None = None,
|
||||||
params: dict | None = ...,
|
params: dict | None = ...,
|
||||||
data: Union[dict, str, None] = ...,
|
data: Union[dict, str, None] = ...,
|
||||||
json: Union[dict, str, None] = ...,
|
json: Union[dict, str, None] = ...,
|
||||||
@ -96,30 +96,28 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
|
|
||||||
def ele(self,
|
def ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, SessionElement],
|
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, SessionElement],
|
||||||
timeout: float = ...) -> Union[ChromiumElement, SessionElement, ChromiumFrame, str, None]: ...
|
timeout: float = None) -> Union[ChromiumElement, SessionElement, ChromiumFrame, str, None]: ...
|
||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, SessionElement, ChromiumFrame, str]]: ...
|
timeout: float = None) -> List[Union[ChromiumElement, SessionElement, ChromiumFrame, str]]: ...
|
||||||
|
|
||||||
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str] = ...) \
|
def s_ele(self, loc_or_ele: Union[Tuple[str, str], str] = None) \
|
||||||
-> Union[SessionElement, str, None]: ...
|
-> Union[SessionElement, str, None]: ...
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def change_mode(self, mode: str = ..., go: bool = ..., copy_cookies: bool = ...) -> None: ...
|
def change_mode(self, mode: str = None, go: bool = True, copy_cookies: bool = True) -> None: ...
|
||||||
|
|
||||||
def cookies_to_session(self, copy_user_agent: bool = ...) -> None: ...
|
def cookies_to_session(self, copy_user_agent: bool = True) -> None: ...
|
||||||
|
|
||||||
def cookies_to_driver(self) -> None: ...
|
def cookies_to_driver(self) -> None: ...
|
||||||
|
|
||||||
def get_cookies(self, as_dict: bool = ..., all_domains: bool = ...) -> Union[dict, list]: ...
|
def get_cookies(self, as_dict: bool = False, all_domains: bool = False) -> Union[dict, list]: ...
|
||||||
|
|
||||||
def _get_driver_cookies(self, as_dict: bool = ...)->dict: ...
|
def _get_driver_cookies(self, as_dict: bool = False) -> dict: ...
|
||||||
|
|
||||||
def set_cookies(self, cookies, set_session: bool = ..., set_driver: bool = ...) -> None: ...
|
def set_cookies(self, cookies, set_session: bool = False, set_driver: bool = False) -> None: ...
|
||||||
|
|
||||||
def check_page(self, by_requests: bool = ...) -> Union[bool, None]: ...
|
|
||||||
|
|
||||||
def close_driver(self) -> None: ...
|
def close_driver(self) -> None: ...
|
||||||
|
|
||||||
@ -128,12 +126,12 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
# ----------------重写SessionPage的函数-----------------------
|
# ----------------重写SessionPage的函数-----------------------
|
||||||
def post(self,
|
def post(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool | None = ...,
|
data: Union[dict, str, None] = None,
|
||||||
retry: int | None = ...,
|
show_errmsg: bool = False,
|
||||||
interval: float | None = ...,
|
retry: int | None = None,
|
||||||
|
interval: float | None = None,
|
||||||
timeout: float | None = ...,
|
timeout: float | None = ...,
|
||||||
params: dict | None = ...,
|
params: dict | None = ...,
|
||||||
data: Union[dict, str, None] = ...,
|
|
||||||
json: Union[dict, str, None] = ...,
|
json: Union[dict, str, None] = ...,
|
||||||
headers: dict | None = ...,
|
headers: dict | None = ...,
|
||||||
cookies: Any | None = ...,
|
cookies: Any | None = ...,
|
||||||
@ -151,7 +149,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
|
|
||||||
def _ele(self,
|
def _ele(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, SessionElement, ChromiumFrame],
|
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, SessionElement, ChromiumFrame],
|
||||||
timeout: float = ..., single: bool = ..., relative: bool = ...) \
|
timeout: float = None, single: bool = True, relative: bool = False) \
|
||||||
-> Union[ChromiumElement, SessionElement, ChromiumFrame, str, None, List[Union[SessionElement, str]], List[
|
-> Union[ChromiumElement, SessionElement, ChromiumFrame, str, None, List[Union[SessionElement, str]], List[
|
||||||
Union[ChromiumElement, str, ChromiumFrame]]]: ...
|
Union[ChromiumElement, str, ChromiumFrame]]]: ...
|
||||||
|
|
||||||
|
@ -55,11 +55,11 @@ ac = ActionChains(page)
|
|||||||
|
|
||||||
**参数:**
|
**参数:**
|
||||||
|
|
||||||
| 名称 | 数据类型 | 说明 |
|
| 名称 | 数据类型 | 默认值 | 说明 |
|
||||||
| ------------ | ----------------------------------------- | --------------------------------------- |
|
| ------------ | ----------------------------------------- | --- | --------------------------------------- |
|
||||||
| `ele_or_loc` | `ChrmoiumElement`、`str`、`Tuple[int, int]` | 元素对象、文本定位符或绝对坐标,坐标为`tuple`(int, int) 形式 |
|
| `ele_or_loc` | `ChrmoiumElement`、`str`、`Tuple[int, int]` | 无 | 元素对象、文本定位符或绝对坐标,坐标为`tuple`(int, int) 形式 |
|
||||||
| `offset_x` | `int` | 偏移量 x |
|
| `offset_x` | `int` | 0 | x 轴偏移量,向右为正,向左为负 |
|
||||||
| `offset_y` | `int` | 偏移量 y |
|
| `offset_y` | `int` | 0 | y 轴偏移量,向下为正,向上为负 |
|
||||||
|
|
||||||
**返回:**
|
**返回:**
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user