diff --git a/DrissionPage/_pages/chromium_page.py b/DrissionPage/_pages/chromium_page.py index 0a77acb..fc18ff0 100644 --- a/DrissionPage/_pages/chromium_page.py +++ b/DrissionPage/_pages/chromium_page.py @@ -71,8 +71,9 @@ class ChromiumPage(ChromiumBase): def _run_browser(self): """连接浏览器""" self._browser = Browser(self._chromium_options.address, self._browser_id, self) - if (self._is_exist and self._chromium_options._headless is False and - 'headless' in self._browser.run_cdp('Browser.getVersion')['userAgent'].lower()): + r = self._browser.run_cdp('Browser.getVersion') + self._browser_version = r['product'] + if self._is_exist and self._chromium_options._headless is False and 'headless' in r['userAgent'].lower(): self._browser.quit(3) connect_browser(self._chromium_options) ws = get(f'http://{self._chromium_options.address}/json/version', headers={'Connection': 'close'}) @@ -140,6 +141,11 @@ class ChromiumPage(ChromiumBase): """返回浏览器进程id""" return self.browser.process_id + @property + def browser_version(self): + """返回所控制的浏览器版本号""" + return self._browser_version + def save(self, path=None, name=None, as_pdf=False, **kwargs): """把当前页面保存为文件,如果path和name参数都为None,只返回文本 :param path: 保存路径,为None且name不为None时保存在当前路径 diff --git a/DrissionPage/_pages/chromium_page.pyi b/DrissionPage/_pages/chromium_page.pyi index 8806b77..2b7115f 100644 --- a/DrissionPage/_pages/chromium_page.pyi +++ b/DrissionPage/_pages/chromium_page.pyi @@ -37,6 +37,7 @@ class ChromiumPage(ChromiumBase): self._rect: Optional[TabRect] = ... self._is_exist: bool = ... self._lock: Lock = ... + self._browser_version: str = ... def _handle_options(self, addr_or_opts: Union[str, ChromiumOptions]) -> str: ... @@ -62,6 +63,9 @@ class ChromiumPage(ChromiumBase): @property def process_id(self) -> Optional[int]: ... + @property + def browser_version(self) -> str: ... + @property def set(self) -> ChromiumPageSetter: ... diff --git a/DrissionPage/_units/actions.py b/DrissionPage/_units/actions.py index 6fcf2f0..171a68f 100644 --- a/DrissionPage/_units/actions.py +++ b/DrissionPage/_units/actions.py @@ -305,6 +305,7 @@ class Actions: :return: None """ self.owner.wait(second=second, scope=scope) + return self def _get_key_data(self, key, action): """获取用于发送的按键信息 diff --git a/DrissionPage/_units/listener.py b/DrissionPage/_units/listener.py index dc981f7..afe171e 100644 --- a/DrissionPage/_units/listener.py +++ b/DrissionPage/_units/listener.py @@ -528,8 +528,14 @@ class Request(object): self._postData = postData return self._postData + @property + def cookies(self): + """以list形式返回发送的cookies""" + return [c['cookie'] for c in self.extra_info.associatedCookies if not c['blockedReasons']] + @property def extra_info(self): + """返回额外数据""" return RequestExtraInfo(self._data_packet._request_extra_info or {}) diff --git a/DrissionPage/_units/listener.pyi b/DrissionPage/_units/listener.pyi index 5de2033..7020af6 100644 --- a/DrissionPage/_units/listener.pyi +++ b/DrissionPage/_units/listener.pyi @@ -62,6 +62,11 @@ class Listener(object): fit_count: bool = True, raise_err: bool = None) -> Union[List[DataPacket], DataPacket, None]: ... + def steps(self, + count: int = None, + timeout: float = None, + gap=1) -> Iterable[Union[DataPacket, List[DataPacket]]]: ... + @property def results(self) -> Union[DataPacket, Dict[str, List[DataPacket]], False]: ... @@ -83,11 +88,6 @@ class Listener(object): def _loading_failed(self, **kwargs) -> None: ... - def steps(self, - count: int = None, - timeout: float = None, - gap=1) -> Iterable[Union[DataPacket, List[DataPacket]]]: ... - def _set_callback(self) -> None: ... @@ -174,6 +174,9 @@ class Request(object): @property def postData(self) -> Any: ... + @property + def cookies(self) -> List[dict]: ... + @property def extra_info(self) -> Optional[RequestExtraInfo]: ...