From cbec20fc97658ad42b354cb4be6e2f88346de069 Mon Sep 17 00:00:00 2001 From: g1879 Date: Tue, 30 Jan 2024 17:05:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=AA=E5=9B=BE=E5=B7=A6=E4=B8=8A=E5=92=8C?= =?UTF-8?q?=E5=8F=B3=E4=B8=8B=E5=8F=82=E6=95=B0=E5=8F=AF=E5=8F=AA=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E5=85=B6=E4=B8=AD=E4=B8=80=E4=B8=AA=EF=BC=9B=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=AF=B9=E8=B1=A1save()=E5=8F=AF=E7=94=9F=E6=88=90?= =?UTF-8?q?=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_configs/chromium_options.py | 4 ++-- DrissionPage/_configs/options_manage.py | 3 +++ DrissionPage/_configs/options_manage.pyi | 4 ++-- DrissionPage/_configs/session_options.py | 4 ++-- DrissionPage/_pages/chromium_base.py | 6 +++++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/DrissionPage/_configs/chromium_options.py b/DrissionPage/_configs/chromium_options.py index d483967..0a5a9e7 100644 --- a/DrissionPage/_configs/chromium_options.py +++ b/DrissionPage/_configs/chromium_options.py @@ -532,9 +532,9 @@ class ChromiumOptions(object): path = path / 'config.ini' if path.is_dir() else path if path.exists(): - om = OptionsManager(str(path)) + om = OptionsManager(path) else: - om = OptionsManager(self.ini_path or str(Path(__file__).parent / 'configs.ini')) + om = OptionsManager(self.ini_path or (Path(__file__).parent / 'configs.ini')) # 设置chromium_options attrs = ('address', 'browser_path', 'arguments', 'extensions', 'user', 'load_mode', diff --git a/DrissionPage/_configs/options_manage.py b/DrissionPage/_configs/options_manage.py index e6867e3..f9c85f4 100644 --- a/DrissionPage/_configs/options_manage.py +++ b/DrissionPage/_configs/options_manage.py @@ -29,6 +29,8 @@ class OptionsManager(object): self.ini_path = default_configs elif path == 'default': self.ini_path = default_configs + elif isinstance(path, Path): + self.ini_path = path else: self.ini_path = Path(path) @@ -147,6 +149,7 @@ class OptionsManager(object): path = Path(path).absolute() path = path / 'config.ini' if path.is_dir() else path + path.parent.mkdir(exist_ok=True, parents=True) path = str(path) self._conf.write(open(path, 'w', encoding='utf-8')) diff --git a/DrissionPage/_configs/options_manage.pyi b/DrissionPage/_configs/options_manage.pyi index 80e438d..f2b0483 100644 --- a/DrissionPage/_configs/options_manage.pyi +++ b/DrissionPage/_configs/options_manage.pyi @@ -7,7 +7,7 @@ """ from configparser import RawConfigParser from pathlib import Path -from typing import Any, Optional +from typing import Any, Optional, Union class OptionsManager(object): @@ -15,7 +15,7 @@ class OptionsManager(object): file_exists: bool = ... _conf: RawConfigParser = ... - def __init__(self, path: str = None): ... + def __init__(self, path: Union[Path, str] = None): ... def __getattr__(self, item) -> dict: ... diff --git a/DrissionPage/_configs/session_options.py b/DrissionPage/_configs/session_options.py index 6373441..a3318ed 100644 --- a/DrissionPage/_configs/session_options.py +++ b/DrissionPage/_configs/session_options.py @@ -377,9 +377,9 @@ class SessionOptions(object): path = path / 'config.ini' if path.is_dir() else path if path.exists(): - om = OptionsManager(str(path)) + om = OptionsManager(path) else: - om = OptionsManager(self.ini_path or str(Path(__file__).parent / 'configs.ini')) + om = OptionsManager(self.ini_path or (Path(__file__).parent / 'configs.ini')) options = session_options_to_dict(self) diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index 92cb9a7..45225f1 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -1064,7 +1064,11 @@ class ChromiumBase(BasePage): vp = {'x': 0, 'y': 0, 'width': width, 'height': height, 'scale': 1} args = {'format': pic_type, 'captureBeyondViewport': True, 'clip': vp} else: - if left_top and right_bottom: + if left_top or right_bottom: + if not left_top: + left_top = (0, 0) + if not right_bottom: + right_bottom = self.rect.size x, y = left_top w = right_bottom[0] - x h = right_bottom[1] - y