From a11267c8a34a4bfab0db633c9f7fc22a8fca4390 Mon Sep 17 00:00:00 2001 From: g1879 Date: Tue, 12 Dec 2023 17:09:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_configs/chromium_options.py | 24 +++++++++++----------- DrissionPage/_configs/chromium_options.pyi | 4 ++-- DrissionPage/_configs/session_options.py | 2 +- DrissionPage/_functions/tools.py | 2 +- DrissionPage/_units/actions.pyi | 14 ++++++++----- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/DrissionPage/_configs/chromium_options.py b/DrissionPage/_configs/chromium_options.py index 8c71fa8..ddbbece 100644 --- a/DrissionPage/_configs/chromium_options.py +++ b/DrissionPage/_configs/chromium_options.py @@ -124,16 +124,6 @@ class ChromiumOptions(object): """返回代理设置""" return self._proxy - @property - def debugger_address(self): - """返回浏览器地址,ip:port""" - return self._address - - @debugger_address.setter - def debugger_address(self, address): - """设置浏览器地址,格式ip:port""" - self.set_address(address) - @property def address(self): """返回浏览器地址,ip:port""" @@ -278,7 +268,7 @@ class ChromiumOptions(object): return self def clear_flags_in_file(self): - """删除浏览器设置文件中已设置的实验项""" + """删除浏览器配置文件中已设置的实验项""" self.clear_file_flags = True return self @@ -370,7 +360,7 @@ class ChromiumOptions(object): """ if search(r'.*?:.*?@.*?\..*', proxy): print('你似乎在设置使用账号密码的代理,暂时不支持这种代理,可自行用插件实现需求。') - if not proxy.lower().startswith('socks'): + if proxy.lower().startswith('socks'): print('你似乎在设置使用socks代理,暂时不支持这种代理,可自行用插件实现需求。') self._proxy = proxy return self.set_argument('--proxy-server', proxy) @@ -558,6 +548,16 @@ class ChromiumOptions(object): # ---------------即将废弃-------------- + @property + def debugger_address(self): + """返回浏览器地址,ip:port""" + return self._address + + @debugger_address.setter + def debugger_address(self, address): + """设置浏览器地址,格式ip:port""" + self.set_address(address) + def set_page_load_strategy(self, value): return self.set_load_mode(value) diff --git a/DrissionPage/_configs/chromium_options.pyi b/DrissionPage/_configs/chromium_options.pyi index 8398182..7a0d7c8 100644 --- a/DrissionPage/_configs/chromium_options.pyi +++ b/DrissionPage/_configs/chromium_options.pyi @@ -4,7 +4,7 @@ @Contact : g1879@qq.com """ from pathlib import Path -from typing import Union, Tuple, Any +from typing import Union, Tuple, Any, Literal class ChromiumOptions(object): @@ -121,7 +121,7 @@ class ChromiumOptions(object): def ignore_certificate_errors(self, on_off=True) -> ChromiumOptions: ... - def set_load_mode(self, value: str) -> ChromiumOptions: ... + def set_load_mode(self, value: Literal['normal', 'eager', 'none']) -> ChromiumOptions: ... def set_browser_path(self, path: Union[str, Path]) -> ChromiumOptions: ... diff --git a/DrissionPage/_configs/session_options.py b/DrissionPage/_configs/session_options.py index 14525b8..f68d6b0 100644 --- a/DrissionPage/_configs/session_options.py +++ b/DrissionPage/_configs/session_options.py @@ -89,7 +89,7 @@ class SessionOptions(object): """返回默认下载路径属性信息""" return self._download_path - def set_download_path(self, path=None): + def set_download_path(self, path): """设置默认下载路径 :param path: 下载路径 :return: 返回当前对象 diff --git a/DrissionPage/_functions/tools.py b/DrissionPage/_functions/tools.py index a7cc6fb..77a9d56 100644 --- a/DrissionPage/_functions/tools.py +++ b/DrissionPage/_functions/tools.py @@ -232,7 +232,7 @@ def stop_process_on_port(port): for proc in process_iter(['pid', 'connections']): try: connections = proc.connections() - except AccessDenied: + except (AccessDenied, NoSuchProcess): continue for conn in connections: if conn.laddr.port == int(port): diff --git a/DrissionPage/_units/actions.pyi b/DrissionPage/_units/actions.pyi index 9f8f717..94663e0 100644 --- a/DrissionPage/_units/actions.pyi +++ b/DrissionPage/_units/actions.pyi @@ -9,8 +9,8 @@ from .._base.chromium_driver import ChromiumDriver from .._elements.chromium_element import ChromiumElement from .._pages.chromium_base import ChromiumBase -KEYS = Literal['NULL', 'CANCEL', 'HELP', 'BACKSPACE', 'BACK_SPACE', -'TAB', 'CLEAR', 'RETURN', 'ENTER', 'SHIFT', 'LEFT_SHIFT', 'CONTROL', +KEYS = Literal['NULL', 'CANCEL', 'HELP', 'BACKSPACE', 'BACK_SPACE', 'meta', +'TAB', 'CLEAR', 'RETURN', 'ENTER', 'SHIFT', 'LEFT_SHIFT', 'CONTROL', 'command ', 'CTRL', 'LEFT_CONTROL', 'ALT', 'LEFT_ALT', 'PAUSE', 'ESCAPE', 'SPACE', 'PAGE_UP', 'PAGE_DOWN', 'END', 'HOME', 'LEFT', 'ARROW_LEFT', 'UP', 'ARROW_UP', 'RIGHT', 'ARROW_RIGHT', 'DOWN', 'ARROW_DOWN', 'INSERT', @@ -25,14 +25,18 @@ KEYS = Literal['NULL', 'CANCEL', 'HELP', 'BACKSPACE', 'BACK_SPACE', 'semicolon', 'equals', 'numpad0', 'numpad1', 'numpad2', 'numpad3', 'numpad4', 'numpad5', 'numpad6', 'numpad7', 'numpad8', 'numpad9', 'multiply', 'add', 'subtract', 'decimal', 'divide', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', -'meta', 'command ', '\ue000', '\ue002', '\ue003', '\ue004', '\ue005', '\ue006', '\ue007', '\ue008', '\ue009', '\ue009', '\ue00a', '\ue00b', '\ue00c', '\ue00d', '\ue00e', '\ue00f', '\ue010', '\ue011', '\ue012', '\ue013', '\ue014', '\ue015', '\ue016', '\ue017', '\ue017', '\ue018', '\ue019', '\ue01a', '\ue01b', '\ue01c', '\ue01d', '\ue01e', '\ue01f', '\ue020', '\ue021', '\ue022', '\ue023', '\ue024', '\ue025', '\ue027', '\ue028', '\ue029', '\ue031', '\ue032', '\ue033', '\ue034', -'\ue035', '\ue036', '\ue037', '\ue038', '\ue039', '\ue03a', '\ue03b', '\ue03c', '\ue03d', '\ue03d' -] +'\ue035', '\ue036', '\ue037', '\ue038', '\ue039', '\ue03a', '\ue03b', '\ue03c', '\ue03d', '\ue03d', +'`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 'q', 'w', +'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\', 'a', 's', 'd', 'f', +'g', 'h', 'j', 'k', 'l', ';', '\'', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', +'.', '/', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', +'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 'A', 'S', 'D', +'F', 'G', 'H', 'J', 'K', 'L', ':', '"', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?'] class Actions: