diff --git a/DrissionPage/_base/base.py b/DrissionPage/_base/base.py index 22ced5a..b71730a 100644 --- a/DrissionPage/_base/base.py +++ b/DrissionPage/_base/base.py @@ -85,7 +85,7 @@ class BaseElement(BaseParser): class DrissionElement(BaseElement): """ChromiumElement 和 SessionElement的基类 - 但不是ShadowRootElement的基类""" + 但不是ShadowRoot的基类""" @property def link(self): diff --git a/DrissionPage/_configs/chromium_options.py b/DrissionPage/_configs/chromium_options.py index ddbbece..c055d0b 100644 --- a/DrissionPage/_configs/chromium_options.py +++ b/DrissionPage/_configs/chromium_options.py @@ -599,19 +599,19 @@ class ChromiumOptions(object): class PortFinder(object): used_port = {} + lock = Lock() def __init__(self): self.tmp_dir = Path(gettempdir()) / 'DrissionPage' / 'TempFolder' self.tmp_dir.mkdir(parents=True, exist_ok=True) if not PortFinder.used_port: clean_folder(self.tmp_dir) - self._lock = Lock() def get_port(self): """查找一个可用端口 :return: 可以使用的端口和用户文件夹路径组成的元组 """ - with self._lock: + with PortFinder.lock: for i in range(9600, 19600): if i in PortFinder.used_port: continue diff --git a/DrissionPage/_configs/chromium_options.pyi b/DrissionPage/_configs/chromium_options.pyi index 7a0d7c8..5531f57 100644 --- a/DrissionPage/_configs/chromium_options.pyi +++ b/DrissionPage/_configs/chromium_options.pyi @@ -4,6 +4,7 @@ @Contact : g1879@qq.com """ from pathlib import Path +from threading import Lock from typing import Union, Tuple, Any, Literal @@ -152,6 +153,7 @@ class ChromiumOptions(object): class PortFinder(object): used_port: dict = ... + lock: Lock = ... @staticmethod def get_port() -> Tuple[int, str]: ... diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index ebc6f7d..9769a80 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -159,7 +159,7 @@ class ChromiumElement(DrissionElement): if not info.get('shadowRoots', None): return None - return ChromiumShadowRoot(self, backend_id=info['shadowRoots'][0]['backendNodeId']) + return ShadowRoot(self, backend_id=info['shadowRoots'][0]['backendNodeId']) @property def sr(self): @@ -764,8 +764,8 @@ class ChromiumElement(DrissionElement): return self.rect.size -class ChromiumShadowRoot(BaseElement): - """ChromiumShadowRoot是用于处理ShadowRoot的类,使用方法和ChromiumElement基本一致""" +class ShadowRoot(BaseElement): + """ShadowRoot是用于处理ShadowRoot的类,使用方法和ChromiumElement基本一致""" def __init__(self, parent_ele, obj_id=None, backend_id=None): """ @@ -786,7 +786,7 @@ class ChromiumShadowRoot(BaseElement): self._states = None def __repr__(self): - return f'' + return f'' def __call__(self, loc_or_str, timeout=None): """在内部查找元素 @@ -1278,7 +1278,7 @@ def run_js(page_or_ele, script, as_expr=False, timeout=None, args=None): :param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]... :return: js执行结果 """ - if isinstance(page_or_ele, (ChromiumElement, ChromiumShadowRoot)): + if isinstance(page_or_ele, (ChromiumElement, ShadowRoot)): page = page_or_ele.page obj_id = page_or_ele._obj_id is_page = False @@ -1337,7 +1337,7 @@ def parse_js_result(page, ele, result): elif sub_type == 'node': class_name = result['className'] if class_name == 'ShadowRoot': - return ChromiumShadowRoot(ele, obj_id=result['objectId']) + return ShadowRoot(ele, obj_id=result['objectId']) elif class_name == 'HTMLDocument': return result else: diff --git a/DrissionPage/_elements/chromium_element.pyi b/DrissionPage/_elements/chromium_element.pyi index 95efc22..e4598d0 100644 --- a/DrissionPage/_elements/chromium_element.pyi +++ b/DrissionPage/_elements/chromium_element.pyi @@ -80,10 +80,10 @@ class ChromiumElement(DrissionElement): def pseudo(self) -> Pseudo: ... @property - def shadow_root(self) -> Union[None, ChromiumShadowRoot]: ... + def shadow_root(self) -> Union[None, ShadowRoot]: ... @property - def sr(self) -> Union[None, ChromiumShadowRoot]: ... + def sr(self) -> Union[None, ShadowRoot]: ... @property def scroll(self) -> ElementScroller: ... @@ -205,7 +205,7 @@ class ChromiumElement(DrissionElement): def _get_ele_path(self, mode: str) -> str: ... -class ChromiumShadowRoot(BaseElement): +class ShadowRoot(BaseElement): def __init__(self, parent_ele: ChromiumElement, obj_id: str = None, backend_id: str = None): self._obj_id: str = ... @@ -300,7 +300,7 @@ def make_chromium_ele(page: ChromiumBase, node_id: str = ..., obj_id: str = ...) def make_js_for_find_ele_by_xpath(xpath: str, type_txt: str, node_txt: str) -> str: ... -def run_js(page_or_ele: Union[ChromiumBase, ChromiumElement, ChromiumShadowRoot], script: str, +def run_js(page_or_ele: Union[ChromiumBase, ChromiumElement, ShadowRoot], script: str, as_expr: bool = False, timeout: float = None, args: tuple = ...) -> Any: ... diff --git a/DrissionPage/_elements/session_element.py b/DrissionPage/_elements/session_element.py index 6bd6326..be1402f 100644 --- a/DrissionPage/_elements/session_element.py +++ b/DrissionPage/_elements/session_element.py @@ -349,7 +349,7 @@ def make_session_ele(html_or_ele, loc=None, single=True): page = None html_or_ele = fromstring(html_or_ele) - # ShadowRootElement, ChromiumShadowRoot, ChromiumFrame + # ShadowRoot, ChromiumFrame elif isinstance(html_or_ele, BaseElement) or the_type.endswith(".ChromiumFrame'>"): page = html_or_ele.page html_or_ele = fromstring(html_or_ele.html) diff --git a/DrissionPage/_functions/web.py b/DrissionPage/_functions/web.py index 030c181..96258dd 100644 --- a/DrissionPage/_functions/web.py +++ b/DrissionPage/_functions/web.py @@ -250,7 +250,8 @@ def set_browser_cookies(page, cookies): if 'expiry' in cookie: cookie['expires'] = int(cookie['expiry']) cookie.pop('expiry') - if 'expires' in cookie: + + if 'expires' in cookie and isinstance(cookie['expires'], str): if cookie['expires'].isdigit(): cookie['expires'] = int(cookie['expires']) diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index 437502c..4843b65 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -190,7 +190,7 @@ class ChromiumBase(BasePage): print('在FrameStartedLoading变成loading') self._doc_got = False - self._ready_state = 'loading' + self._ready_state = 'connecting' self._is_loading = True self._load_end_time = perf_counter() + self.timeouts.page_load if self._load_mode == 'eager': diff --git a/DrissionPage/_units/listener.py b/DrissionPage/_units/listener.py index 5dd1638..830f3c1 100644 --- a/DrissionPage/_units/listener.py +++ b/DrissionPage/_units/listener.py @@ -173,7 +173,7 @@ class Listener(object): if clear: self.clear() - def go_on(self): + def resume(self): """继续暂停的监听""" if self.listening: return diff --git a/DrissionPage/_units/listener.pyi b/DrissionPage/_units/listener.pyi index 12eb344..d38d8be 100644 --- a/DrissionPage/_units/listener.pyi +++ b/DrissionPage/_units/listener.pyi @@ -38,7 +38,7 @@ class Listener(object): def pause(self, clear: bool = True) -> None: ... - def go_on(self) -> None: ... + def resume(self) -> None: ... def wait(self, count: int = 1, timeout: float = None, fit_count: bool = True, raise_err: bool = None) -> Union[List[DataPacket], DataPacket, None]: ... diff --git a/DrissionPage/_units/states.py b/DrissionPage/_units/states.py index a53da2a..00dfde9 100644 --- a/DrissionPage/_units/states.py +++ b/DrissionPage/_units/states.py @@ -129,12 +129,12 @@ class PageStates(object): @property def ready_state(self): - """返回当前页面加载状态,'loading' 'interactive' 'complete'""" + """返回当前页面加载状态,'connecting' 'loading' 'interactive' 'complete'""" return self._page._ready_state @property def has_alert(self): - """返回当前页面加载状态,'loading' 'interactive' 'complete'""" + """返回当前页面是否存在弹窗""" return self._page._has_alert diff --git a/DrissionPage/_units/states.pyi b/DrissionPage/_units/states.pyi index 0bad17b..102b1ea 100644 --- a/DrissionPage/_units/states.pyi +++ b/DrissionPage/_units/states.pyi @@ -5,7 +5,7 @@ """ from typing import Union, Tuple, List, Optional -from .._elements.chromium_element import ChromiumShadowRoot, ChromiumElement +from .._elements.chromium_element import ShadowRoot, ChromiumElement from .._pages.chromium_base import ChromiumBase from .._pages.chromium_frame import ChromiumFrame @@ -43,11 +43,11 @@ class ElementStates(object): class ShadowRootStates(object): - def __init__(self, ele: ChromiumShadowRoot): + def __init__(self, ele: ShadowRoot): """ :param ele: ChromiumElement """ - self._ele: ChromiumShadowRoot = ... + self._ele: ShadowRoot = ... @property def is_enabled(self) -> bool: ...