From a0ffd4707a44fdc6b04cbfd4bf5e5705a4937632 Mon Sep 17 00:00:00 2001 From: g1879 Date: Thu, 23 Feb 2023 10:55:46 +0800 Subject: [PATCH] =?UTF-8?q?3.2.1=E9=BB=98=E8=AE=A4=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E6=94=B9=E4=B8=BA=E7=94=A8=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=EF=BC=9Bwait=E5=A2=9E=E5=8A=A0download=5Fbegin()?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=9Bcommon=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E6=94=B9=E5=90=8D=E4=B8=BAcommons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/__init__.py | 2 +- DrissionPage/action_chains.py | 4 +- DrissionPage/base.py | 6 +-- DrissionPage/base.pyi | 2 +- DrissionPage/chromium_base.py | 12 ++--- DrissionPage/chromium_base.pyi | 8 +-- DrissionPage/chromium_element.py | 53 +++++++++---------- DrissionPage/chromium_element.pyi | 2 +- DrissionPage/chromium_page.py | 44 ++++++++++----- DrissionPage/chromium_page.pyi | 13 +++-- DrissionPage/{common => commons}/browser.py | 0 DrissionPage/{common => commons}/browser.pyi | 0 DrissionPage/{common => commons}/cli.py | 0 DrissionPage/{common => commons}/constants.py | 0 DrissionPage/{common => commons}/keys.py | 0 DrissionPage/{common => commons}/locator.py | 0 DrissionPage/{common => commons}/locator.pyi | 0 DrissionPage/{common => commons}/tools.py | 0 DrissionPage/{common => commons}/tools.pyi | 0 DrissionPage/{common => commons}/web.py | 0 DrissionPage/{common => commons}/web.pyi | 0 DrissionPage/configs/chromium_options.py | 2 +- DrissionPage/configs/session_options.py | 2 +- DrissionPage/easy_set.py | 4 +- DrissionPage/mixpage/base.py | 4 +- DrissionPage/mixpage/drission.py | 6 +-- DrissionPage/mixpage/driver_element.py | 6 +-- DrissionPage/mixpage/driver_page.py | 2 +- DrissionPage/mixpage/session_element.py | 4 +- DrissionPage/mixpage/session_page.py | 2 +- DrissionPage/mixpage/shadow_root_element.py | 2 +- DrissionPage/session_element.py | 6 +-- DrissionPage/session_element.pyi | 2 +- DrissionPage/session_page.py | 2 +- DrissionPage/session_page.pyi | 2 +- setup.py | 6 +-- 36 files changed, 112 insertions(+), 86 deletions(-) rename DrissionPage/{common => commons}/browser.py (100%) rename DrissionPage/{common => commons}/browser.pyi (100%) rename DrissionPage/{common => commons}/cli.py (100%) rename DrissionPage/{common => commons}/constants.py (100%) rename DrissionPage/{common => commons}/keys.py (100%) rename DrissionPage/{common => commons}/locator.py (100%) rename DrissionPage/{common => commons}/locator.pyi (100%) rename DrissionPage/{common => commons}/tools.py (100%) rename DrissionPage/{common => commons}/tools.pyi (100%) rename DrissionPage/{common => commons}/web.py (100%) rename DrissionPage/{common => commons}/web.pyi (100%) diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index f002879..82e1b7d 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -14,7 +14,7 @@ from .configs.session_options import SessionOptions # 常用工具 from .action_chains import ActionChains -from .common.keys import Keys +from .commons.keys import Keys # 旧版页面类和启动配置类 try: diff --git a/DrissionPage/action_chains.py b/DrissionPage/action_chains.py index cfb9dc5..e2111bd 100644 --- a/DrissionPage/action_chains.py +++ b/DrissionPage/action_chains.py @@ -5,8 +5,8 @@ """ from time import sleep -from .common.keys import modifierBit, keyDescriptionForString -from .common.web import location_in_viewport +from .commons.keys import modifierBit, keyDescriptionForString +from .commons.web import location_in_viewport class ActionChains: diff --git a/DrissionPage/base.py b/DrissionPage/base.py index 16496b3..443d8c5 100644 --- a/DrissionPage/base.py +++ b/DrissionPage/base.py @@ -7,9 +7,9 @@ from abc import abstractmethod from re import sub from urllib.parse import quote -from .common.constants import Settings, NoneElement -from .common.locator import get_loc -from .common.web import format_html +from .commons.constants import Settings, NoneElement +from .commons.locator import get_loc +from .commons.web import format_html from .errors import ElementNotFoundError diff --git a/DrissionPage/base.pyi b/DrissionPage/base.pyi index 17533c5..c40c4cc 100644 --- a/DrissionPage/base.pyi +++ b/DrissionPage/base.pyi @@ -6,7 +6,7 @@ from abc import abstractmethod from typing import Union, Tuple, List -from .common.constants import NoneElement +from .commons.constants import NoneElement class BaseParser(object): diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index be47d53..3da7fbf 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -14,10 +14,10 @@ from .base import BasePage from .chromium_driver import ChromiumDriver from .chromium_element import ChromiumWaiter, ChromiumScroll, ChromiumElement, run_js, make_chromium_ele, \ ChromiumElementWaiter -from .common.constants import HANDLE_ALERT_METHOD, ERROR, NoneElement -from .common.locator import get_loc -from .common.tools import get_usable_path -from .common.web import cookies_to_tuple +from .commons.constants import HANDLE_ALERT_METHOD, ERROR, NoneElement +from .commons.locator import get_loc +from .commons.tools import get_usable_path +from .commons.web import cookies_to_tuple from .errors import ContextLossError, ElementLossError, AlertExistsError, CallMethodError, TabClosedError, \ NoRectError from .session_element import make_session_ele @@ -312,7 +312,7 @@ class ChromiumBase(BasePage): def wait(self): """返回用于等待的对象""" if self._wait is None: - self._wait = ChromiumPageWaiter(self) + self._wait = ChromiumBaseWaiter(self) return self._wait @property @@ -901,7 +901,7 @@ class ChromiumBaseSetter(object): self._page.run_cdp('Network.setExtraHTTPHeaders', headers=headers) -class ChromiumPageWaiter(ChromiumWaiter): +class ChromiumBaseWaiter(ChromiumWaiter): def __init__(self, page): """ :param page: 所属页面对象 diff --git a/DrissionPage/chromium_base.pyi b/DrissionPage/chromium_base.pyi index fc9fb09..36db3cf 100644 --- a/DrissionPage/chromium_base.pyi +++ b/DrissionPage/chromium_base.pyi @@ -10,7 +10,7 @@ from DataRecorder import Recorder from requests import Session from requests.cookies import RequestsCookieJar -from .common.constants import NoneElement +from .commons.constants import NoneElement from .base import BasePage from .chromium_driver import ChromiumDriver from .chromium_element import ChromiumElement, ChromiumScroll, ChromiumWaiter @@ -38,7 +38,7 @@ class ChromiumBase(BasePage): self._debug: bool = ... self._debug_recorder: Recorder = ... self._upload_list: list = ... - self._wait: ChromiumPageWaiter = ... + self._wait: ChromiumBaseWaiter = ... self._set: ChromiumBaseSetter = ... def _connect_browser(self, tab_id: str = None) -> None: ... @@ -113,7 +113,7 @@ class ChromiumBase(BasePage): def upload_list(self) -> list: ... @property - def wait(self) -> ChromiumPageWaiter: ... + def wait(self) -> ChromiumBaseWaiter: ... @property def set(self) -> ChromiumBaseSetter: ... @@ -193,7 +193,7 @@ class ChromiumBase(BasePage): timeout: float = None) -> Union[bool, None]: ... -class ChromiumPageWaiter(ChromiumWaiter): +class ChromiumBaseWaiter(ChromiumWaiter): def __init__(self, page: ChromiumBase): self._driver: ChromiumBase = ... diff --git a/DrissionPage/chromium_element.py b/DrissionPage/chromium_element.py index 1c408a6..d8212fc 100644 --- a/DrissionPage/chromium_element.py +++ b/DrissionPage/chromium_element.py @@ -10,20 +10,20 @@ from time import perf_counter, sleep from warnings import warn from .base import DrissionElement, BaseElement -from .common.constants import FRAME_ELEMENT, NoneElement, Settings -from .common.keys import keys_to_typing, keyDescriptionForString, keyDefinitions -from .common.locator import get_loc -from .common.web import make_absolute_link, get_ele_txt, format_html, is_js_func, location_in_viewport, offset_scroll +from .commons.constants import FRAME_ELEMENT, NoneElement, Settings +from .commons.keys import keys_to_typing, keyDescriptionForString, keyDefinitions +from .commons.locator import get_loc +from .commons.web import make_absolute_link, get_ele_txt, format_html, is_js_func, location_in_viewport, offset_scroll from .errors import ContextLossError, ElementLossError, JavaScriptError, NoRectError, ElementNotFoundError, \ CallMethodError from .session_element import make_session_ele class ChromiumElement(DrissionElement): - """ChromePage页面对象中的元素对象""" + """控制浏览器元素的对象""" def __init__(self, page, node_id=None, obj_id=None, backend_id=None): - """初始化,node_id、obj_id和backend_id必须至少传入一个 + """node_id、obj_id和backend_id必须至少传入一个 :param page: 元素所在ChromePage页面对象 :param node_id: cdp中的node id :param obj_id: js中的object id @@ -66,7 +66,6 @@ class ChromiumElement(DrissionElement): def __call__(self, loc_or_str, timeout=None): """在内部查找元素 - 例:ele2 = ele1('@id=ele_id') :param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串 :param timeout: 超时时间 :return: ChromiumElement对象或属性、文本 @@ -97,7 +96,7 @@ class ChromiumElement(DrissionElement): try: attrs = self.page.run_cdp('DOM.getAttributes', nodeId=self._node_id)['attributes'] return {attrs[i]: attrs[i + 1] for i in range(0, len(attrs), 2)} - except CallMethodError: + except CallMethodError: # 文档根元素不能调用此方法 return {} @property @@ -118,7 +117,7 @@ class ChromiumElement(DrissionElement): @property def size(self): - """返回元素宽和高""" + """返回元素宽和高组成的元组""" model = self.page.run_cdp('DOM.getBoxModel', backendNodeId=self._backend_id)['model'] return model['height'], model['width'] @@ -277,7 +276,7 @@ class ChromiumElement(DrissionElement): return super().afters(filter_loc, timeout) def attr(self, attr): - """返回attribute属性值 + """返回一个attribute属性值 :param attr: 属性名 :return: 属性值文本,没有该属性返回None """ @@ -308,14 +307,14 @@ class ChromiumElement(DrissionElement): return attrs.get(attr, None) def remove_attr(self, attr): - """删除元素attribute属性 + """删除元素一个attribute属性 :param attr: 属性名 :return: None """ self.run_js(f'this.removeAttribute("{attr}");') def prop(self, prop): - """获取property属性值 + """获取一个property属性值 :param prop: 属性名 :return: 属性值文本 """ @@ -328,7 +327,7 @@ class ChromiumElement(DrissionElement): return format_html(i['value']['value']) def run_js(self, script, *args, as_expr=False): - """运行javascript代码 + """对本元素执行javascript代码 :param script: js文本 :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... :param as_expr: 是否作为表达式运行,为True时args无效 @@ -337,7 +336,7 @@ class ChromiumElement(DrissionElement): return run_js(self, script, as_expr, self.page.timeouts.script, args) def run_async_js(self, script, *args, as_expr=False): - """以异步方式执行js代码 + """以异步方式对本元素执行javascript代码 :param script: js文本 :param args: 参数,按顺序在js文本中对应argument[0]、argument[1]... :param as_expr: 是否作为表达式运行,为True时args无效 @@ -363,7 +362,7 @@ class ChromiumElement(DrissionElement): return self._ele(loc_or_str, timeout=timeout, single=False) def s_ele(self, loc_or_str=None): - """查找第一个符合条件的元素以SessionElement形式返回,处理复杂页面时效率很高 + """查找第一个符合条件的元素,以SessionElement形式返回 :param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串 :return: SessionElement对象或属性、文本 """ @@ -372,7 +371,7 @@ class ChromiumElement(DrissionElement): return make_session_ele(self, loc_or_str) def s_eles(self, loc_or_str=None): - """查找所有符合条件的元素以SessionElement列表形式返回 + """查找所有符合条件的元素,以SessionElement列表形式返回 :param loc_or_str: 定位符 :return: SessionElement或属性、文本组成的列表 """ @@ -450,7 +449,7 @@ class ChromiumElement(DrissionElement): f.write(data) def get_screenshot(self, path=None, as_bytes=None): - """对当前元素截图 + """对当前元素截图,可保存到文件,或以字节方式返回 :param path: 完整路径,后缀可选 'jpg','jpeg','png','webp' :param as_bytes: 是否已字节形式返回图片,可选 'jpg','jpeg','png','webp',生效时path参数无效 :return: 图片完整路径或字节文本 @@ -475,7 +474,7 @@ class ChromiumElement(DrissionElement): left_top=left_top, right_bottom=right_bottom) def input(self, vals, clear=True): - """输入文本或组合键,也可用于输入文件路径到input元素(文件间用\n间隔) + """输入文本或组合键,也可用于输入文件路径到input元素(路径间用\n间隔) :param vals: 文本值或按键组合 :param clear: 输入前是否清空文本框 :return: None @@ -509,7 +508,7 @@ class ChromiumElement(DrissionElement): def clear(self, by_js=False): """清空元素文本 - :param by_js: 是否用js方式清空 + :param by_js: 是否用js方式清空,为False则用全选+del模拟输入删除 :return: None """ if by_js: @@ -541,7 +540,7 @@ class ChromiumElement(DrissionElement): self.drag_to((offset_x, offset_y), speed) def drag_to(self, ele_or_loc, speed=40): - """拖拽当前元素,目标为另一个元素或坐标元组 + """拖拽当前元素,目标为另一个元素或坐标元组(x, y) :param ele_or_loc: 另一个元素或坐标元组,坐标为元素中点的坐标 :param speed: 拖动的速度,传入0即瞬间到达 :return: None @@ -575,7 +574,7 @@ class ChromiumElement(DrissionElement): actions.release() def _get_obj_id(self, node_id=None, backend_id=None): - """根据传入node id获取js中的object id + """根据传入node id或backend id获取js中的object id :param node_id: cdp中的node id :param backend_id: backend id :return: js中的object id @@ -586,7 +585,7 @@ class ChromiumElement(DrissionElement): return self.page.run_cdp('DOM.resolveNode', backendNodeId=backend_id)['object']['objectId'] def _get_node_id(self, obj_id=None, backend_id=None): - """根据传入object id获取cdp中的node id + """根据传入object id或backend id获取cdp中的node id :param obj_id: js中的object id :param backend_id: backend id :return: cdp中的node id @@ -604,7 +603,7 @@ class ChromiumElement(DrissionElement): return self.page.run_cdp('DOM.describeNode', nodeId=node_id)['node']['backendNodeId'] def _get_ele_path(self, mode): - """返获取css路径或xpath路径""" + """返获取绝对的css路径或xpath路径""" if mode == 'xpath': txt1 = 'var tag = el.nodeName.toLowerCase();' txt3 = ''' && sib.nodeName.toLowerCase()==tag''' @@ -644,7 +643,7 @@ class ChromiumElement(DrissionElement): return f':root{t}' if mode == 'css' else t def _set_file_input(self, files): - """往上传控件写入路径 + """对上传控件写入路径 :param files: 文件路径列表或字符串,字符串时多个文件用回车分隔 :return: None """ @@ -1997,7 +1996,7 @@ class ChromiumWaiter(object): self._driver = page_or_ele def ele_delete(self, loc_or_ele, timeout=None): - """ + """等待元素从DOM中删除 :param loc_or_ele: 要等待的元素,可以是已有元素、定位符 :param timeout: 超时时间,默认读取页面超时时间 :return: 是否等待成功 @@ -2005,7 +2004,7 @@ class ChromiumWaiter(object): return ChromiumElementWaiter(self._driver, loc_or_ele, timeout).delete() def ele_display(self, loc_or_ele, timeout=None): - """ + """等待元素变成显示状态 :param loc_or_ele: 要等待的元素,可以是已有元素、定位符 :param timeout: 超时时间,默认读取页面超时时间 :return: 是否等待成功 @@ -2013,7 +2012,7 @@ class ChromiumWaiter(object): return ChromiumElementWaiter(self._driver, loc_or_ele, timeout).display() def ele_hidden(self, loc_or_ele, timeout=None): - """ + """等待元素变成隐藏状态 :param loc_or_ele: 要等待的元素,可以是已有元素、定位符 :param timeout: 超时时间,默认读取页面超时时间 :return: 是否等待成功 diff --git a/DrissionPage/chromium_element.pyi b/DrissionPage/chromium_element.pyi index e122e23..4641bc8 100644 --- a/DrissionPage/chromium_element.pyi +++ b/DrissionPage/chromium_element.pyi @@ -10,7 +10,7 @@ from .base import DrissionElement, BaseElement from .chromium_base import ChromiumBase from .chromium_frame import ChromiumFrame from .chromium_page import ChromiumPage -from .common.constants import NoneElement +from .commons.constants import NoneElement from .session_element import SessionElement from .web_page import WebPage diff --git a/DrissionPage/chromium_page.py b/DrissionPage/chromium_page.py index 06d2bf2..43c443e 100644 --- a/DrissionPage/chromium_page.py +++ b/DrissionPage/chromium_page.py @@ -11,11 +11,11 @@ from warnings import warn from requests import Session -from .chromium_base import ChromiumBase, Timeout, ChromiumBaseSetter +from .chromium_base import ChromiumBase, Timeout, ChromiumBaseSetter, ChromiumBaseWaiter from .chromium_driver import ChromiumDriver from .chromium_tab import ChromiumTab -from .common.browser import connect_browser -from .common.web import set_session_cookies +from .commons.browser import connect_browser +from .commons.web import set_session_cookies from .configs.chromium_options import ChromiumOptions from .errors import CallMethodError from .session_page import DownloadSetter @@ -106,7 +106,7 @@ class ChromiumPage(ChromiumBase): self._tab_obj.Page.javascriptDialogClosed = self._on_alert_close self._main_tab = self.tab_id try: - self.download_set.by_DownloadKit() + self.download_set.by_browser() except RuntimeError: pass @@ -178,6 +178,13 @@ class ChromiumPage(ChromiumBase): self._rect = ChromiumTabRect(self) return self._rect + @property + def wait(self): + """返回用于等待的对象""" + if self._wait is None: + self._wait = ChromiumPageWaiter(self) + return self._wait + def get_tab(self, tab_id=None): """获取一个标签页对象 :param tab_id: 要获取的标签页id,为None时获取当前tab @@ -253,13 +260,6 @@ class ChromiumPage(ChromiumBase): if read_doc and self.ready_state == 'complete': self._get_document() - def wait_download_begin(self, timeout=None): - """等待浏览器下载开始 - :param timeout: 等待超时时间,为None则使用页面对象timeout属性 - :return: 是否等到下载开始 - """ - return self.download_set.wait_download_begin(timeout) - def close_tabs(self, tab_ids=None, others=False): """关闭传入的标签页,默认关闭当前页。可传入多个 :param tab_ids: 要关闭的标签页id,可传入id组成的列表或元组,为None时关闭当前页 @@ -372,6 +372,23 @@ class ChromiumPage(ChromiumBase): warn("set_window()方法即将弃用,请用set.window.xxxx()方法代替。", DeprecationWarning) return WindowSetter(self) + def wait_download_begin(self, timeout=None): + """等待浏览器下载开始 + :param timeout: 等待超时时间,为None则使用页面对象timeout属性 + :return: 是否等到下载开始 + """ + warn("wait_download_begin()方法即将弃用,请用wait.download_begin()方法代替。", DeprecationWarning) + return self.download_set.wait_download_begin(timeout) + + +class ChromiumPageWaiter(ChromiumBaseWaiter): + def download_begin(self, timeout=None): + """等待浏览器下载开始 + :param timeout: 等待超时时间,为None则使用页面对象timeout属性 + :return: 是否等到下载开始 + """ + return self._driver.download_set.wait_download_begin(timeout) + class ChromiumTabRect(object): def __init__(self, page): @@ -526,7 +543,7 @@ class ChromiumDownloadSetter(DownloadSetter): def _cookies_to_session(self): """把driver对象的cookies复制到session对象""" - ua = self._page.driver.Runtime.evaluate(expression='navigator.userAgent;')['result']['value'] + ua = self._page.run_cdp('Runtime.evaluate', expression='navigator.userAgent;')['result']['value'] self.session.headers.update({"User-Agent": ua}) set_session_cookies(self.session, self._page.get_cookies(as_dict=True)) @@ -576,6 +593,9 @@ class WindowSetter(object): """用于设置窗口大小的类""" def __init__(self, page): + """ + :param page: 页面对象 + """ self._page = page self._window_id = self._get_info()['windowId'] diff --git a/DrissionPage/chromium_page.pyi b/DrissionPage/chromium_page.pyi index 7852103..4e4b994 100644 --- a/DrissionPage/chromium_page.pyi +++ b/DrissionPage/chromium_page.pyi @@ -11,7 +11,7 @@ from typing import Union, Tuple, List from DownloadKit import DownloadKit from requests import Session -from .chromium_base import ChromiumBase, ChromiumBaseSetter +from .chromium_base import ChromiumBase, ChromiumBaseSetter, ChromiumBaseWaiter from .chromium_driver import ChromiumDriver from .chromium_tab import ChromiumTab from .configs.chromium_options import ChromiumOptions @@ -55,6 +55,9 @@ class ChromiumPage(ChromiumBase): @property def rect(self) -> ChromiumTabRect: ... + @property + def wait(self) -> ChromiumPageWaiter: ... + @property def main_tab(self) -> str: ... @@ -88,8 +91,6 @@ class ChromiumPage(ChromiumBase): def _to_tab(self, tab_id: str = None, activate: bool = True, read_doc: bool = True) -> None: ... - def wait_download_begin(self, timeout: Union[int, float] = None) -> bool: ... - 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) -> None: ... @@ -107,6 +108,12 @@ class ChromiumPage(ChromiumBase): def _on_alert_open(self, **kwargs): ... +class ChromiumPageWaiter(ChromiumBaseWaiter): + _driver: ChromiumPage = ... + + def download_begin(self, timeout: Union[int, float] = None) -> bool: ... + + class ChromiumTabRect(object): def __init__(self, page: ChromiumPage): self._page: ChromiumPage = ... diff --git a/DrissionPage/common/browser.py b/DrissionPage/commons/browser.py similarity index 100% rename from DrissionPage/common/browser.py rename to DrissionPage/commons/browser.py diff --git a/DrissionPage/common/browser.pyi b/DrissionPage/commons/browser.pyi similarity index 100% rename from DrissionPage/common/browser.pyi rename to DrissionPage/commons/browser.pyi diff --git a/DrissionPage/common/cli.py b/DrissionPage/commons/cli.py similarity index 100% rename from DrissionPage/common/cli.py rename to DrissionPage/commons/cli.py diff --git a/DrissionPage/common/constants.py b/DrissionPage/commons/constants.py similarity index 100% rename from DrissionPage/common/constants.py rename to DrissionPage/commons/constants.py diff --git a/DrissionPage/common/keys.py b/DrissionPage/commons/keys.py similarity index 100% rename from DrissionPage/common/keys.py rename to DrissionPage/commons/keys.py diff --git a/DrissionPage/common/locator.py b/DrissionPage/commons/locator.py similarity index 100% rename from DrissionPage/common/locator.py rename to DrissionPage/commons/locator.py diff --git a/DrissionPage/common/locator.pyi b/DrissionPage/commons/locator.pyi similarity index 100% rename from DrissionPage/common/locator.pyi rename to DrissionPage/commons/locator.pyi diff --git a/DrissionPage/common/tools.py b/DrissionPage/commons/tools.py similarity index 100% rename from DrissionPage/common/tools.py rename to DrissionPage/commons/tools.py diff --git a/DrissionPage/common/tools.pyi b/DrissionPage/commons/tools.pyi similarity index 100% rename from DrissionPage/common/tools.pyi rename to DrissionPage/commons/tools.pyi diff --git a/DrissionPage/common/web.py b/DrissionPage/commons/web.py similarity index 100% rename from DrissionPage/common/web.py rename to DrissionPage/commons/web.py diff --git a/DrissionPage/common/web.pyi b/DrissionPage/commons/web.pyi similarity index 100% rename from DrissionPage/common/web.pyi rename to DrissionPage/commons/web.pyi diff --git a/DrissionPage/configs/chromium_options.py b/DrissionPage/configs/chromium_options.py index 0c3ce60..915db73 100644 --- a/DrissionPage/configs/chromium_options.py +++ b/DrissionPage/configs/chromium_options.py @@ -6,7 +6,7 @@ from pathlib import Path from tempfile import gettempdir, TemporaryDirectory -from DrissionPage.common.tools import port_is_using, clean_folder +from DrissionPage.commons.tools import port_is_using, clean_folder from .options_manage import OptionsManager diff --git a/DrissionPage/configs/session_options.py b/DrissionPage/configs/session_options.py index 8bf8e66..eaa763b 100644 --- a/DrissionPage/configs/session_options.py +++ b/DrissionPage/configs/session_options.py @@ -8,7 +8,7 @@ from pathlib import Path from requests import Session from requests.structures import CaseInsensitiveDict -from DrissionPage.common.web import cookies_to_tuple, set_session_cookies +from DrissionPage.commons.web import cookies_to_tuple, set_session_cookies from .options_manage import OptionsManager diff --git a/DrissionPage/easy_set.py b/DrissionPage/easy_set.py index c860c2d..51d7e6c 100644 --- a/DrissionPage/easy_set.py +++ b/DrissionPage/easy_set.py @@ -8,8 +8,8 @@ from pathlib import Path from re import search from typing import Union -from .common.constants import Settings -from .common.tools import unzip +from .commons.constants import Settings +from .commons.tools import unzip from .configs.chromium_options import ChromiumOptions from .configs.options_manage import OptionsManager from .session_page import SessionPage diff --git a/DrissionPage/mixpage/base.py b/DrissionPage/mixpage/base.py index 1a26364..80048bb 100644 --- a/DrissionPage/mixpage/base.py +++ b/DrissionPage/mixpage/base.py @@ -7,8 +7,8 @@ from abc import abstractmethod from re import sub from urllib.parse import quote -from DrissionPage.common.web import format_html -from DrissionPage.common.locator import get_loc +from DrissionPage.commons.web import format_html +from DrissionPage.commons.locator import get_loc class BaseParser(object): diff --git a/DrissionPage/mixpage/drission.py b/DrissionPage/mixpage/drission.py index de76a4a..b977cd8 100644 --- a/DrissionPage/mixpage/drission.py +++ b/DrissionPage/mixpage/drission.py @@ -14,9 +14,9 @@ from selenium.webdriver.chrome.options import Options from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver from tldextract import extract -from DrissionPage.common.tools import get_pid_from_port -from DrissionPage.common.browser import connect_browser -from DrissionPage.common.web import cookies_to_tuple +from DrissionPage.commons.tools import get_pid_from_port +from DrissionPage.commons.browser import connect_browser +from DrissionPage.commons.web import cookies_to_tuple from DrissionPage.configs.session_options import SessionOptions, session_options_to_dict from DrissionPage.configs.driver_options import DriverOptions diff --git a/DrissionPage/mixpage/driver_element.py b/DrissionPage/mixpage/driver_element.py index f88967f..c467918 100644 --- a/DrissionPage/mixpage/driver_element.py +++ b/DrissionPage/mixpage/driver_element.py @@ -15,9 +15,9 @@ from selenium.webdriver.support import expected_conditions as ec from selenium.webdriver.support.wait import WebDriverWait from .base import DrissionElement, BaseElement -from DrissionPage.common.locator import str_to_loc, get_loc -from DrissionPage.common.tools import get_usable_path -from DrissionPage.common.web import format_html, get_ele_txt +from DrissionPage.commons.locator import str_to_loc, get_loc +from DrissionPage.commons.tools import get_usable_path +from DrissionPage.commons.web import format_html, get_ele_txt from .session_element import make_session_ele diff --git a/DrissionPage/mixpage/driver_page.py b/DrissionPage/mixpage/driver_page.py index 122a86a..2f9fcfd 100644 --- a/DrissionPage/mixpage/driver_page.py +++ b/DrissionPage/mixpage/driver_page.py @@ -13,7 +13,7 @@ from selenium.webdriver.remote.webelement import WebElement from selenium.webdriver.support.wait import WebDriverWait from .base import BasePage -from DrissionPage.common.tools import get_usable_path +from DrissionPage.commons.tools import get_usable_path from .driver_element import DriverElement, make_driver_ele, Scroll, ElementWaiter from .session_element import make_session_ele diff --git a/DrissionPage/mixpage/session_element.py b/DrissionPage/mixpage/session_element.py index 07a9fcb..1e0ebc1 100644 --- a/DrissionPage/mixpage/session_element.py +++ b/DrissionPage/mixpage/session_element.py @@ -10,8 +10,8 @@ from lxml.etree import tostring from lxml.html import HtmlElement, fromstring from .base import DrissionElement, BasePage, BaseElement -from DrissionPage.common.locator import get_loc -from DrissionPage.common.web import get_ele_txt, make_absolute_link +from DrissionPage.commons.locator import get_loc +from DrissionPage.commons.web import get_ele_txt, make_absolute_link class SessionElement(DrissionElement): diff --git a/DrissionPage/mixpage/session_page.py b/DrissionPage/mixpage/session_page.py index 14cb169..345b51d 100644 --- a/DrissionPage/mixpage/session_page.py +++ b/DrissionPage/mixpage/session_page.py @@ -15,7 +15,7 @@ from tldextract import extract from .base import BasePage from DrissionPage.configs.session_options import SessionOptions -from DrissionPage.common.web import cookie_to_dict, set_session_cookies +from DrissionPage.commons.web import cookie_to_dict, set_session_cookies from .session_element import SessionElement, make_session_ele diff --git a/DrissionPage/mixpage/shadow_root_element.py b/DrissionPage/mixpage/shadow_root_element.py index dd4f9ab..ec195e5 100644 --- a/DrissionPage/mixpage/shadow_root_element.py +++ b/DrissionPage/mixpage/shadow_root_element.py @@ -9,7 +9,7 @@ from typing import Union from selenium.webdriver.remote.webelement import WebElement from .base import BaseElement -from DrissionPage.common.locator import get_loc +from DrissionPage.commons.locator import get_loc from .driver_element import make_driver_ele from .session_element import make_session_ele, SessionElement diff --git a/DrissionPage/session_element.py b/DrissionPage/session_element.py index e7b88d9..bf23079 100644 --- a/DrissionPage/session_element.py +++ b/DrissionPage/session_element.py @@ -10,9 +10,9 @@ from lxml.etree import tostring from lxml.html import HtmlElement, fromstring from .base import DrissionElement, BasePage, BaseElement -from .common.constants import NoneElement -from .common.locator import get_loc -from .common.web import get_ele_txt, make_absolute_link +from .commons.constants import NoneElement +from .commons.locator import get_loc +from .commons.web import get_ele_txt, make_absolute_link class SessionElement(DrissionElement): diff --git a/DrissionPage/session_element.pyi b/DrissionPage/session_element.pyi index 311d09f..1d3cc5d 100644 --- a/DrissionPage/session_element.pyi +++ b/DrissionPage/session_element.pyi @@ -11,7 +11,7 @@ from .base import DrissionElement, BaseElement from .chromium_base import ChromiumBase from .chromium_element import ChromiumElement from .chromium_frame import ChromiumFrame -from .common.constants import NoneElement +from .commons.constants import NoneElement from .driver_element import DriverElement from .driver_page import DriverPage from .session_page import SessionPage diff --git a/DrissionPage/session_page.py b/DrissionPage/session_page.py index a8d0d35..2447e78 100644 --- a/DrissionPage/session_page.py +++ b/DrissionPage/session_page.py @@ -14,7 +14,7 @@ from requests.structures import CaseInsensitiveDict from tldextract import extract from .base import BasePage -from .common.web import cookie_to_dict, set_session_cookies +from .commons.web import cookie_to_dict, set_session_cookies from .configs.session_options import SessionOptions from .session_element import SessionElement, make_session_ele diff --git a/DrissionPage/session_page.pyi b/DrissionPage/session_page.pyi index 64acef6..f6d9299 100644 --- a/DrissionPage/session_page.pyi +++ b/DrissionPage/session_page.pyi @@ -13,7 +13,7 @@ from requests.auth import HTTPBasicAuth from requests.cookies import RequestsCookieJar from requests.structures import CaseInsensitiveDict -from .common.constants import NoneElement +from .commons.constants import NoneElement from .base import BasePage from .chromium_page import ChromiumPage from .configs.session_options import SessionOptions diff --git a/setup.py b/setup.py index 8e40038..75065bd 100644 --- a/setup.py +++ b/setup.py @@ -6,10 +6,10 @@ with open("README.md", "r", encoding='utf-8') as fh: setup( name="DrissionPage", - version="3.2.0", + version="3.2.1", author="g1879", author_email="g1879@qq.com", - description="A module that integrates selenium and requests session, encapsulates common page operations.", + description="Python based web automation tool. It can control the browser and send and receive data packets.", long_description=long_description, long_description_content_type="text/markdown", license="BSD", @@ -36,7 +36,7 @@ setup( python_requires='>=3.6', entry_points={ 'console_scripts': [ - 'dp = DrissionPage.common.cli:main', + 'dp = DrissionPage.commons.cli:main', ], }, )