From 830b2258aff5774f60d7b0b5793353389a4f05f2 Mon Sep 17 00:00:00 2001 From: g1879 Date: Tue, 13 Dec 2022 17:33:53 +0800 Subject: [PATCH] =?UTF-8?q?3.0.21=EF=BC=8C=E8=B0=83=E6=95=B4WebPage?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E5=85=83=E7=B4=A0=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E7=9A=84prev()=E3=80=81next()=E3=80=81before()=E3=80=81after()?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_base.py | 24 ++++++++--------- DrissionPage/chromium_base.pyi | 8 +++--- DrissionPage/chromium_element.py | 44 +++++++++++++++---------------- DrissionPage/chromium_element.pyi | 21 ++++++++------- docs/版本历史.md | 10 ++++++- setup.py | 2 +- 6 files changed, 59 insertions(+), 50 deletions(-) diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index 085f8cd..60762f7 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -703,41 +703,41 @@ class ChromiumFrame(ChromiumBase): """ return self._inner_ele.parent(level_or_loc) - def prev(self, index=1, filter_loc='', timeout=0): + def prev(self, filter_loc='', index=1, timeout=0): """返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n - :param index: 前面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 前面第几个查询结果元素 :param timeout: 查找元素的超时时间 :return: 兄弟元素 """ - return self._inner_ele.prev(index, filter_loc, timeout) + return self._inner_ele.prev(filter_loc, index, timeout) - def next(self, index=1, filter_loc='', timeout=0): + def next(self, filter_loc='', index=1, timeout=0): """返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n - :param index: 后面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 后面第几个查询结果元素 :param timeout: 查找元素的超时时间 :return: 兄弟元素 """ - return self._inner_ele.next(index, filter_loc, timeout) + return self._inner_ele.next(filter_loc, index, timeout) - def before(self, index=1, filter_loc='', timeout=None): + def before(self, filter_loc='', index=1, timeout=None): """返回当前元素前面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档 \n - :param index: 前面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 前面第几个查询结果元素 :param timeout: 查找元素的超时时间 :return: 本元素前面的某个元素或节点 """ - return self._inner_ele.before(index, filter_loc, timeout) + return self._inner_ele.before(filter_loc, index, timeout) - def after(self, index=1, filter_loc='', timeout=None): + def after(self, filter_loc='', index=1, timeout=None): """返回当前元素后面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档 \n - :param index: 后面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 后面第几个查询结果元素 :param timeout: 查找元素的超时时间 :return: 本元素后面的某个元素或节点 """ - return self._inner_ele.after(index, filter_loc, timeout) + return self._inner_ele.after(filter_loc, index, timeout) def prevs(self, filter_loc='', timeout=0): """返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选 \n diff --git a/DrissionPage/chromium_base.pyi b/DrissionPage/chromium_base.pyi index 460de0a..427c5d7 100644 --- a/DrissionPage/chromium_base.pyi +++ b/DrissionPage/chromium_base.pyi @@ -232,23 +232,23 @@ class ChromiumFrame(ChromiumBase): def parent(self, level_or_loc: Union[tuple, str, int] = ...) -> Union['ChromiumElement', None]: ... def prev(self, - index: int = ..., filter_loc: Union[tuple, str] = ..., + index: int = ..., timeout: float = ...) -> Union['ChromiumElement', str, None]: ... def next(self, - index: int = ..., filter_loc: Union[tuple, str] = ..., + index: int = ..., timeout: float = ...) -> Union['ChromiumElement', str, None]: ... def before(self, - index: int = ..., filter_loc: Union[tuple, str] = ..., + index: int = ..., timeout: float = ...) -> Union['ChromiumElement', str, None]: ... def after(self, - index: int = ..., filter_loc: Union[tuple, str] = ..., + index: int = ..., timeout: float = ...) -> Union['ChromiumElement', str, None]: ... def prevs(self, diff --git a/DrissionPage/chromium_element.py b/DrissionPage/chromium_element.py index 3db754d..4b4e35f 100644 --- a/DrissionPage/chromium_element.py +++ b/DrissionPage/chromium_element.py @@ -191,37 +191,37 @@ class ChromiumElement(DrissionElement): """ 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 - :param index: 前面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 前面第几个查询结果元素 :param timeout: 查找元素的超时时间 :return: 兄弟元素 """ 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 - :param index: 后面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 后面第几个查询结果元素 :param timeout: 查找元素的超时时间 :return: 兄弟元素 """ 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): """返回当前元素前面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档 \n - :param index: 前面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 前面第几个查询结果元素 :param timeout: 查找元素的超时时间 :return: 本元素前面的某个元素或节点 """ 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): """返回当前元素后面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档 \n - :param index: 后面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 后面第几个查询结果元素 :param timeout: 查找元素的超时时间 :return: 本元素后面的某个元素或节点 """ @@ -907,28 +907,28 @@ class ChromiumShadowRootElement(BaseElement): return self.parent_ele._ele(loc, timeout=0, relative=True) - def next(self, index=1, filter_loc=''): + def next(self, filter_loc='', index=1): """返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n - :param index: 第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 第几个查询结果元素 :return: ChromiumElement对象 """ nodes = self.nexts(filter_loc=filter_loc) return nodes[index - 1] if nodes else None - def before(self, index=1, filter_loc=''): + def before(self, filter_loc='', index=1): """返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n - :param index: 前面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 前面第几个查询结果元素 :return: 本元素前面的某个元素或节点 """ nodes = self.befores(filter_loc=filter_loc) return nodes[index - 1] if nodes else None - def after(self, index=1, filter_loc=''): + def after(self, filter_loc='', index=1): """返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n - :param index: 后面第几个查询结果元素 :param filter_loc: 用于筛选元素的查询语法 + :param index: 后面第几个查询结果元素 :return: 本元素后面的某个元素或节点 """ nodes = self.afters(filter_loc=filter_loc) @@ -1213,48 +1213,48 @@ class ChromiumShadowRootElement(BaseElement): # return self._inner_ele.parent(level_or_loc) # # def prev(self, -# index: int = 1, # filter_loc: Union[tuple, str] = '', +# index: int = 1, # timeout: float = 0) -> Union['ChromiumElement', str, None]: # """返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n -# :param index: 前面第几个查询结果元素 # :param filter_loc: 用于筛选元素的查询语法 +# :param index: 前面第几个查询结果元素 # :param timeout: 查找元素的超时时间 # :return: 兄弟元素 # """ # return self._inner_ele.prev(index, filter_loc, timeout) # # def next(self, -# index: int = 1, # filter_loc: Union[tuple, str] = '', +# index: int = 1, # timeout: float = 0) -> Union['ChromiumElement', str, None]: # """返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个 \n -# :param index: 后面第几个查询结果元素 # :param filter_loc: 用于筛选元素的查询语法 +# :param index: 后面第几个查询结果元素 # :param timeout: 查找元素的超时时间 # :return: 兄弟元素 # """ # return self._inner_ele.next(index, filter_loc, timeout) # # def before(self, -# index: int = 1, # filter_loc: Union[tuple, str] = '', +# index: int = 1, # timeout: float = None) -> Union['ChromiumElement', str, None]: # """返回当前元素前面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档 \n -# :param index: 前面第几个查询结果元素 # :param filter_loc: 用于筛选元素的查询语法 +# :param index: 前面第几个查询结果元素 # :param timeout: 查找元素的超时时间 # :return: 本元素前面的某个元素或节点 # """ # return self._inner_ele.before(index, filter_loc, timeout) # # def after(self, -# index: int = 1, # filter_loc: Union[tuple, str] = '', +# index: int = 1, # timeout: float = None) -> Union['ChromiumElement', str, None]: # """返回当前元素后面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档 \n -# :param index: 后面第几个查询结果元素 # :param filter_loc: 用于筛选元素的查询语法 +# :param index: 后面第几个查询结果元素 # :param timeout: 查找元素的超时时间 # :return: 本元素后面的某个元素或节点 # """ diff --git a/DrissionPage/chromium_element.pyi b/DrissionPage/chromium_element.pyi index c6f3762..794451f 100644 --- a/DrissionPage/chromium_element.pyi +++ b/DrissionPage/chromium_element.pyi @@ -98,23 +98,23 @@ class ChromiumElement(DrissionElement): def parent(self, level_or_loc: Union[tuple, str, int] = ...) -> Union['ChromiumElement', None]: ... def prev(self, - index: int = ..., filter_loc: Union[tuple, str] = ..., + index: int = ..., timeout: float = ...) -> Union['ChromiumElement', str, None]: ... def next(self, - index: int = ..., filter_loc: Union[tuple, str] = ..., + index: int = ..., timeout: float = ...) -> Union['ChromiumElement', str, None]: ... def before(self, - index: int = ..., filter_loc: Union[tuple, str] = ..., + index: int = ..., timeout: float = ...) -> Union['ChromiumElement', str, None]: ... def after(self, - index: int = ..., filter_loc: Union[tuple, str] = ..., + index: int = ..., timeout: float = ...) -> Union['ChromiumElement', str, None]: ... def prevs(self, @@ -274,15 +274,16 @@ class ChromiumShadowRootElement(BaseElement): def parent(self, level_or_loc: Union[str, int] = ...) -> ChromiumElement: ... def next(self, - index: int = ..., - filter_loc: Union[tuple, str] = ...) -> Union[ChromiumElement, str, None]: ... + filter_loc: Union[tuple, str] = ..., + index: int = ...) -> Union[ChromiumElement, str, None]: ... def before(self, - index: int = ..., - filter_loc: Union[tuple, str] = ...) -> Union[ChromiumElement, str, None]: ... + filter_loc: Union[tuple, str] = ..., + index: int = ...) -> Union[ChromiumElement, str, None]: ... - def after(self, index: int = ..., - filter_loc: Union[tuple, str] = ...) -> Union[ChromiumElement, str, None]: ... + def after(self, + filter_loc: Union[tuple, str] = ..., + index: int = ...) -> Union[ChromiumElement, str, None]: ... def nexts(self, filter_loc: Union[tuple, str] = ...) -> List[Union[ChromiumElement, str]]: ... diff --git a/docs/版本历史.md b/docs/版本历史.md index 2639e57..ded6328 100644 --- a/docs/版本历史.md +++ b/docs/版本历史.md @@ -1,4 +1,12 @@ -# v3.0.8 +# v3.0.21 + +- `change_mode()`增加`copy_cookies`参数 + +- ###### 调整`WebPage`生成的元素对象的`prev()`、`next()`、`before()`、`after()`参数顺序 + +- 用存根文件取代类型注解 + +# v3.0.20 重大更新。推出`WebPage`,重新开发底层逻辑,摆脱对 selenium 的依赖,增强了功能,提升了运行效率。支持 chromium 内核的浏览器(如 chrome 和 edge)。比`MixPage`有以下优点: diff --git a/setup.py b/setup.py index 5dc995b..5831d04 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh: setup( name="DrissionPage", - version="3.0.20", + version="3.0.21", author="g1879", author_email="g1879@qq.com", description="A module that integrates selenium and requests session, encapsulates common page operations.",