From 517da31d30293cfaeaa5fe9875199ae0914465de Mon Sep 17 00:00:00 2001 From: g1879 Date: Thu, 22 Dec 2022 10:17:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/__init__.py | 4 ++++ DrissionPage/action_chains.py | 4 ++++ DrissionPage/action_chains.pyi | 4 ++++ DrissionPage/base.py | 1 - DrissionPage/base.pyi | 4 ++++ DrissionPage/chromium_base.py | 12 ++++++------ DrissionPage/chromium_base.pyi | 4 ++++ DrissionPage/chromium_element.py | 27 ++++++++++++++++----------- DrissionPage/chromium_element.pyi | 5 ++--- DrissionPage/chromium_frame.py | 4 ++++ DrissionPage/chromium_frame.pyi | 4 ++++ DrissionPage/chromium_page.py | 4 ++++ DrissionPage/chromium_page.pyi | 4 ++++ DrissionPage/chromium_tab.py | 4 ++++ DrissionPage/chromium_tab.pyi | 4 ++++ DrissionPage/common.py | 1 - DrissionPage/config.py | 2 -- DrissionPage/config.pyi | 4 ++++ DrissionPage/drission.py | 1 - DrissionPage/drission.pyi | 4 ++++ DrissionPage/driver_element.py | 1 - DrissionPage/driver_element.pyi | 4 ++++ DrissionPage/driver_page.py | 1 - DrissionPage/driver_page.pyi | 4 ++++ DrissionPage/easy_set.py | 1 - DrissionPage/keys.py | 4 ++++ DrissionPage/mix_page.py | 1 - DrissionPage/mix_page.pyi | 4 ++++ DrissionPage/session_element.py | 1 - DrissionPage/session_element.pyi | 4 ++++ DrissionPage/session_page.py | 4 ++++ DrissionPage/session_page.pyi | 5 +++++ DrissionPage/shadow_root_element.py | 1 - DrissionPage/shadow_root_element.pyi | 4 ++++ DrissionPage/tab.py | 4 ++++ DrissionPage/tools.py | 2 ++ DrissionPage/web_page.py | 4 ++++ DrissionPage/web_page.pyi | 4 ++++ 38 files changed, 123 insertions(+), 31 deletions(-) diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 092cd3c..3b92ff7 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from warnings import filterwarnings diff --git a/DrissionPage/action_chains.py b/DrissionPage/action_chains.py index db4862b..3c6d40c 100644 --- a/DrissionPage/action_chains.py +++ b/DrissionPage/action_chains.py @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from time import sleep from .common import _location_in_viewport diff --git a/DrissionPage/action_chains.pyi b/DrissionPage/action_chains.pyi index 0efc0bc..f44fd01 100644 --- a/DrissionPage/action_chains.pyi +++ b/DrissionPage/action_chains.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Union, Tuple from .chromium_base import ChromiumBase diff --git a/DrissionPage/base.py b/DrissionPage/base.py index a88484b..420985a 100644 --- a/DrissionPage/base.py +++ b/DrissionPage/base.py @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : base.py """ from abc import abstractmethod from re import sub diff --git a/DrissionPage/base.pyi b/DrissionPage/base.pyi index 26ff642..0175360 100644 --- a/DrissionPage/base.pyi +++ b/DrissionPage/base.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from abc import abstractmethod from typing import Union, Tuple, List diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index c542d9b..6b584e0 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -1,11 +1,15 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from json import loads from time import perf_counter, sleep from requests import Session from .base import BasePage -from .chromium_element import ChromiumElementWaiter, ChromeScroll, ChromiumElement, run_script +from .chromium_element import ChromiumElementWaiter, ChromeScroll, ChromiumElement, run_script, make_chromium_ele from .common import get_loc from .config import cookies_to_tuple from .session_element import make_session_ele @@ -408,11 +412,7 @@ class ChromiumBase(BasePage): toIndex=count) eles = [] for i in nodeIds['nodeIds']: - ele = ChromiumElement(self, node_id=i) - if ele.tag in ('iframe', 'frame'): - from .chromium_frame import ChromiumFrame - ele = ChromiumFrame(self, ele) - eles.append(ele) + eles.append(make_chromium_ele(self, node_id=i)) return eles[0] if single else eles diff --git a/DrissionPage/chromium_base.pyi b/DrissionPage/chromium_base.pyi index 3bca52b..95b690b 100644 --- a/DrissionPage/chromium_base.pyi +++ b/DrissionPage/chromium_base.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Union, Tuple, List, Any from DataRecorder import Recorder diff --git a/DrissionPage/chromium_element.py b/DrissionPage/chromium_element.py index 7001cf5..909c8eb 100644 --- a/DrissionPage/chromium_element.py +++ b/DrissionPage/chromium_element.py @@ -443,7 +443,7 @@ class ChromiumElement(DrissionElement): :param single: True则返回第一个,False则返回全部 :return: ChromiumElement对象或文本、属性或其组成的列表 """ - return make_chromium_ele(self, loc_or_str, single, timeout, relative=relative) + return find_in_chromium_ele(self, loc_or_str, single, timeout, relative=relative) def style(self, style, pseudo_ele=''): """返回元素样式属性值,可获取伪元素属性值 \n @@ -1022,7 +1022,7 @@ class ChromiumShadowRootElement(BaseElement): if single: node_id = self.page.run_cdp('DOM.querySelector', nodeId=self._node_id, selector=css_paths[0], not_change=True)['nodeId'] - return _make_chromium_ele(self.page, node_id=node_id) if node_id else None + return make_chromium_ele(self.page, node_id=node_id) if node_id else None else: results = [] @@ -1030,7 +1030,7 @@ class ChromiumShadowRootElement(BaseElement): node_id = self.page.run_cdp('DOM.querySelector', nodeId=self._node_id, selector=i, not_change=True)['nodeId'] if node_id: - results.append(_make_chromium_ele(self.page, node_id=node_id)) + results.append(make_chromium_ele(self.page, node_id=node_id)) return results def _get_node_id(self, obj_id): @@ -1046,7 +1046,7 @@ class ChromiumShadowRootElement(BaseElement): return self.page.run_cdp('DOM.describeNode', nodeId=node_id, not_change=True)['node']['backendNodeId'] -def make_chromium_ele(ele, loc, single=True, timeout=None, relative=True): +def find_in_chromium_ele(ele, loc, single=True, timeout=None, relative=True): """在chromium元素中查找 \n :param ele: ChromiumElement对象 :param loc: 元素定位元组 @@ -1117,14 +1117,14 @@ def _find_by_xpath(ele, xpath, single, timeout, relative=True): return None else: # return ChromiumElement(ele.page, obj_id=r['result']['objectId']) - return _make_chromium_ele(ele.page, obj_id=r['result']['objectId']) + return make_chromium_ele(ele.page, obj_id=r['result']['objectId']) else: if r['result']['description'] == 'NodeList(0)': return [] else: r = ele.page.driver.Runtime.getProperties(objectId=r['result']['objectId'], ownProperties=True)['result'] - return [_make_chromium_ele(ele.page, obj_id=i['value']['objectId']) + return [make_chromium_ele(ele.page, obj_id=i['value']['objectId']) if i['value']['type'] == 'object' else i['value']['value'] for i in r[:-1]] @@ -1158,18 +1158,23 @@ def _find_by_css(ele, selector, single, timeout): if r['result']['subtype'] == 'null': return None else: - return _make_chromium_ele(ele.page, obj_id=r['result']['objectId']) + return make_chromium_ele(ele.page, obj_id=r['result']['objectId']) else: if r['result']['description'] == 'NodeList(0)': return [] else: r = ele.page.driver.Runtime.getProperties(objectId=r['result']['objectId'], ownProperties=True)['result'] - return [_make_chromium_ele(ele.page, obj_id=i['value']['objectId']) for i in r] + return [make_chromium_ele(ele.page, obj_id=i['value']['objectId']) for i in r] -def _make_chromium_ele(page, node_id=None, obj_id=None): - """根据node id或object id生成相应元素对象""" +def make_chromium_ele(page, node_id=None, obj_id=None): + """根据node id或object id生成相应元素对象 \n + :param page: ChromiumPage对象 + :param node_id: 元素的node id + :param obj_id: 元素的object id + :return: ChromiumElement对象或ChromiumFrame对象 + """ ele = ChromiumElement(page, obj_id=obj_id, node_id=node_id) if ele.tag in ('iframe', 'frame'): from .chromium_frame import ChromiumFrame @@ -1290,7 +1295,7 @@ def _parse_js_result(page, ele, result): elif class_name == 'HTMLDocument': return result else: - return _make_chromium_ele(page, obj_id=result['objectId']) + return make_chromium_ele(page, obj_id=result['objectId']) elif sub_type == 'array': r = page.driver.Runtime.getProperties(objectId=result['result']['objectId'], ownProperties=True)['result'] diff --git a/DrissionPage/chromium_element.pyi b/DrissionPage/chromium_element.pyi index 4bad97e..f070f5e 100644 --- a/DrissionPage/chromium_element.pyi +++ b/DrissionPage/chromium_element.pyi @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : chromium_element.py """ from pathlib import Path from typing import Union, Tuple, List, Any @@ -321,7 +320,7 @@ class ChromiumShadowRootElement(BaseElement): def _get_backend_id(self, node_id: str) -> str: ... -def make_chromium_ele(ele: ChromiumElement, +def find_in_chromium_ele(ele: ChromiumElement, loc: Union[str, Tuple[str, str]], single: bool = ..., timeout: float = ..., @@ -341,7 +340,7 @@ def _find_by_css(ele: ChromiumElement, timeout: float) -> Union[ChromiumElement, List[ChromiumElement], None]: ... -def _make_chromium_ele(page: ChromiumBase, node_id: str = ..., obj_id: str = ...) -> ChromiumElement: ... +def make_chromium_ele(page: ChromiumBase, node_id: str = ..., obj_id: str = ...) -> Union[ChromiumElement, ChromiumFrame]: ... def _make_js_for_find_ele_by_xpath(xpath: str, type_txt: str, node_txt: str) -> str: ... diff --git a/DrissionPage/chromium_frame.py b/DrissionPage/chromium_frame.py index 6b20938..4f9a4c8 100644 --- a/DrissionPage/chromium_frame.py +++ b/DrissionPage/chromium_frame.py @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from re import search from urllib.parse import urlparse diff --git a/DrissionPage/chromium_frame.pyi b/DrissionPage/chromium_frame.pyi index 0f016ba..bb545e8 100644 --- a/DrissionPage/chromium_frame.pyi +++ b/DrissionPage/chromium_frame.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Union, Tuple, List from session_element import SessionElement diff --git a/DrissionPage/chromium_page.py b/DrissionPage/chromium_page.py index f27074b..9d4a8ff 100644 --- a/DrissionPage/chromium_page.py +++ b/DrissionPage/chromium_page.py @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from pathlib import Path from platform import system from re import search diff --git a/DrissionPage/chromium_page.pyi b/DrissionPage/chromium_page.pyi index c9b49d0..7a782c0 100644 --- a/DrissionPage/chromium_page.pyi +++ b/DrissionPage/chromium_page.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from os import popen from pathlib import Path from typing import Union, Tuple, List diff --git a/DrissionPage/chromium_tab.py b/DrissionPage/chromium_tab.py index b9541cb..5a6e685 100644 --- a/DrissionPage/chromium_tab.py +++ b/DrissionPage/chromium_tab.py @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from .chromium_base import ChromiumBase diff --git a/DrissionPage/chromium_tab.pyi b/DrissionPage/chromium_tab.pyi index 9609f51..23da931 100644 --- a/DrissionPage/chromium_tab.pyi +++ b/DrissionPage/chromium_tab.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from .chromium_base import ChromiumBase from .chromium_page import ChromiumPage diff --git a/DrissionPage/common.py b/DrissionPage/common.py index 41ee9af..5245197 100644 --- a/DrissionPage/common.py +++ b/DrissionPage/common.py @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : common.py """ from html import unescape from pathlib import Path diff --git a/DrissionPage/config.py b/DrissionPage/config.py index c86ad89..96db2bd 100644 --- a/DrissionPage/config.py +++ b/DrissionPage/config.py @@ -1,9 +1,7 @@ # -*- coding:utf-8 -*- """ -管理配置的类 @Author : g1879 @Contact : g1879@qq.com -@File : config.py """ from configparser import RawConfigParser, NoSectionError, NoOptionError from http.cookiejar import Cookie diff --git a/DrissionPage/config.pyi b/DrissionPage/config.pyi index 41c7c5a..5e117fd 100644 --- a/DrissionPage/config.pyi +++ b/DrissionPage/config.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from configparser import RawConfigParser from http.cookiejar import Cookie from typing import Any, Union, List diff --git a/DrissionPage/drission.py b/DrissionPage/drission.py index 8692c7b..b8b9dad 100644 --- a/DrissionPage/drission.py +++ b/DrissionPage/drission.py @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : drission.py """ from platform import system from sys import exit diff --git a/DrissionPage/drission.pyi b/DrissionPage/drission.pyi index 74e534e..b85ee4e 100644 --- a/DrissionPage/drission.pyi +++ b/DrissionPage/drission.pyi @@ -1,4 +1,8 @@ # -*- encoding: utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from subprocess import Popen from typing import Union diff --git a/DrissionPage/driver_element.py b/DrissionPage/driver_element.py index b533364..da3fb4c 100644 --- a/DrissionPage/driver_element.py +++ b/DrissionPage/driver_element.py @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : driver_element.py """ from os import sep from pathlib import Path diff --git a/DrissionPage/driver_element.pyi b/DrissionPage/driver_element.pyi index 350812b..a4fc77d 100644 --- a/DrissionPage/driver_element.pyi +++ b/DrissionPage/driver_element.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Union, List, Any, Tuple from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver diff --git a/DrissionPage/driver_page.py b/DrissionPage/driver_page.py index 787fced..9a84e6a 100644 --- a/DrissionPage/driver_page.py +++ b/DrissionPage/driver_page.py @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : driver_page.py """ from glob import glob from os import sep diff --git a/DrissionPage/driver_page.pyi b/DrissionPage/driver_page.pyi index 2e00662..f33acaf 100644 --- a/DrissionPage/driver_page.pyi +++ b/DrissionPage/driver_page.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Union, List, Any, Tuple from selenium.webdriver.chrome.webdriver import WebDriver diff --git a/DrissionPage/easy_set.py b/DrissionPage/easy_set.py index b4a421b..3a03e05 100644 --- a/DrissionPage/easy_set.py +++ b/DrissionPage/easy_set.py @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : driver_page.py """ from os import popen from pathlib import Path diff --git a/DrissionPage/keys.py b/DrissionPage/keys.py index 34a45df..9d94072 100644 --- a/DrissionPage/keys.py +++ b/DrissionPage/keys.py @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import List, Tuple, Dict diff --git a/DrissionPage/mix_page.py b/DrissionPage/mix_page.py index c190aba..e8cddcc 100644 --- a/DrissionPage/mix_page.py +++ b/DrissionPage/mix_page.py @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : mix_page.py """ from .base import BasePage from .drission import Drission diff --git a/DrissionPage/mix_page.pyi b/DrissionPage/mix_page.pyi index 4e98842..7ef00e1 100644 --- a/DrissionPage/mix_page.pyi +++ b/DrissionPage/mix_page.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Union, List, Tuple, Any from DownloadKit import DownloadKit diff --git a/DrissionPage/session_element.py b/DrissionPage/session_element.py index cc610f7..bcabae1 100644 --- a/DrissionPage/session_element.py +++ b/DrissionPage/session_element.py @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : session_element.py """ from re import match, DOTALL diff --git a/DrissionPage/session_element.pyi b/DrissionPage/session_element.pyi index c59bc19..b3c1b07 100644 --- a/DrissionPage/session_element.pyi +++ b/DrissionPage/session_element.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Union, List, Tuple from lxml.html import HtmlElement diff --git a/DrissionPage/session_page.py b/DrissionPage/session_page.py index 81bf9bc..5e42514 100644 --- a/DrissionPage/session_page.py +++ b/DrissionPage/session_page.py @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from re import search from time import sleep from urllib.parse import urlparse diff --git a/DrissionPage/session_page.pyi b/DrissionPage/session_page.pyi index d072f00..9424c85 100644 --- a/DrissionPage/session_page.pyi +++ b/DrissionPage/session_page.pyi @@ -1,3 +1,8 @@ +# -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Any, Union, Tuple, List from DownloadKit import DownloadKit diff --git a/DrissionPage/shadow_root_element.py b/DrissionPage/shadow_root_element.py index 0d5b650..728b566 100644 --- a/DrissionPage/shadow_root_element.py +++ b/DrissionPage/shadow_root_element.py @@ -2,7 +2,6 @@ """ @Author : g1879 @Contact : g1879@qq.com -@File : shadow_root_element.py """ from time import perf_counter from typing import Union diff --git a/DrissionPage/shadow_root_element.pyi b/DrissionPage/shadow_root_element.pyi index 158668c..82eb002 100644 --- a/DrissionPage/shadow_root_element.pyi +++ b/DrissionPage/shadow_root_element.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Union, Any, Tuple, List from selenium.webdriver.remote.webelement import WebElement diff --git a/DrissionPage/tab.py b/DrissionPage/tab.py index a9209e7..dc2fcb2 100644 --- a/DrissionPage/tab.py +++ b/DrissionPage/tab.py @@ -1,4 +1,8 @@ # -*- coding: utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from functools import partial from json import dumps, loads from logging import getLogger diff --git a/DrissionPage/tools.py b/DrissionPage/tools.py index a837ab4..a77e11f 100644 --- a/DrissionPage/tools.py +++ b/DrissionPage/tools.py @@ -1,5 +1,7 @@ # -*- coding:utf-8 -*- """ +@Author : g1879 +@Contact : g1879@qq.com 实用工具 """ from FlowViewer import Listener, RequestMan diff --git a/DrissionPage/web_page.py b/DrissionPage/web_page.py index 6aeb95f..5845ab7 100644 --- a/DrissionPage/web_page.py +++ b/DrissionPage/web_page.py @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from time import sleep from requests import Session diff --git a/DrissionPage/web_page.pyi b/DrissionPage/web_page.pyi index 1e9928b..b2df91c 100644 --- a/DrissionPage/web_page.pyi +++ b/DrissionPage/web_page.pyi @@ -1,4 +1,8 @@ # -*- coding:utf-8 -*- +""" +@Author : g1879 +@Contact : g1879@qq.com +""" from typing import Union, Tuple, List, Any from DownloadKit import DownloadKit