diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 5fa6c0f..f35e197 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -14,4 +14,4 @@ from ._configs.chromium_options import ChromiumOptions from ._configs.session_options import SessionOptions __all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__'] -__version__ = '4.0.4.15' +__version__ = '4.0.4.16' diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index 23e04f4..03235dd 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -557,7 +557,7 @@ class ChromiumElement(DrissionElement): :param path: 文件保存路径,为None时保存到当前文件夹 :param name: 文件名称,为None时从资源url获取 :param timeout: 等待资源加载的超时时间(秒) - :param rename: 是否覆盖重名文件 + :param rename: 遇到重名文件时是否自动重命名 :return: 返回保存路径 """ data = self.src(timeout=timeout) @@ -612,7 +612,7 @@ class ChromiumElement(DrissionElement): return self.owner._get_screenshot(path, name, as_bytes=as_bytes, as_base64=as_base64, full_page=False, left_top=left_top, right_bottom=right_bottom, ele=self) - def input(self, vals, clear=True, by_js=False): + def input(self, vals, clear=False, by_js=False): """输入文本或组合键,也可用于输入文件路径到input元素(路径间用\n间隔) :param vals: 文本值或按键组合 :param clear: 输入前是否清空文本框 diff --git a/DrissionPage/_elements/chromium_element.pyi b/DrissionPage/_elements/chromium_element.pyi index 9164d47..3e7d0da 100644 --- a/DrissionPage/_elements/chromium_element.pyi +++ b/DrissionPage/_elements/chromium_element.pyi @@ -221,7 +221,7 @@ class ChromiumElement(DrissionElement): as_base64: PIC_TYPE = None, scroll_to_center: bool = True) -> Union[str, bytes]: ... - def input(self, vals: Any, clear: bool = True, by_js: bool = False) -> None: ... + def input(self, vals: Any, clear: bool = False, by_js: bool = False) -> None: ... def _set_file_input(self, files: Union[str, list, tuple]) -> None: ... diff --git a/DrissionPage/_units/listener.py b/DrissionPage/_units/listener.py index b24615b..c8f7385 100644 --- a/DrissionPage/_units/listener.py +++ b/DrissionPage/_units/listener.py @@ -216,28 +216,26 @@ class Listener(object): self._running_requests = 0 self._running_targets = 0 - def wait_silent(self, timeout=None, delay=0, targets_only=False): + def wait_silent(self, timeout=None, targets_only=False, limit=0): """等待所有请求结束 :param timeout: 超时,为None时无限等待 - :param delay: 等待成功后延后若干秒再检测,返回最终结果 :param targets_only: 是否只等待targets指定的请求结束 + :param limit: 剩下多少个连接时视为结束 :return: 返回是否等待成功 """ if not self.listening: raise RuntimeError('监听未启动或已暂停。') if timeout is None: - while (not targets_only and self._running_requests > 0) or (targets_only and self._running_targets > 0): + while ((not targets_only and self._running_requests > limit) + or (targets_only and self._running_targets > limit)): sleep(.1) - sleep(delay) - return self._running_targets <= 0 if targets_only else self._running_requests <= 0 + return True - delaying = False end_time = perf_counter() + timeout while perf_counter() < end_time: - if (not targets_only and self._running_requests <= 0) or (targets_only and self._running_targets <= 0): - if delaying: - return True - sleep(delay) + if ((not targets_only and self._running_requests <= limit) + or (targets_only and self._running_targets <= limit)): + return True sleep(.1) else: return False diff --git a/DrissionPage/_units/listener.pyi b/DrissionPage/_units/listener.pyi index 84b048b..afa3e04 100644 --- a/DrissionPage/_units/listener.pyi +++ b/DrissionPage/_units/listener.pyi @@ -72,7 +72,10 @@ class Listener(object): def clear(self) -> None: ... - def wait_silent(self, timeout: float = None, delay: float = 0, targets_only: bool = False) -> bool: ... + def wait_silent(self, + timeout: float = None, + targets_only: bool = False, + limit: int = 0) -> bool: ... def _to_target(self, target_id: str, address: str, owner: ChromiumBase) -> None: ...