From 9690a575024c4e4392f6c229b1cf9588c297d7b7 Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 9 Oct 2023 22:59:41 +0800 Subject: [PATCH] =?UTF-8?q?get=5Fscreenshot()=E5=85=BC=E5=AE=B9=E6=97=A7?= =?UTF-8?q?=E7=89=88=E6=9C=ACpath=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_base.py | 16 +++++++++------- DrissionPage/chromium_frame.py | 17 ++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index 8b379de..80f2d13 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -881,13 +881,15 @@ class ChromiumBase(BasePage): pic_type = 'jpeg' if as_base64 == 'jpg' else as_base64 else: - if not name: - name = f'{self.title}.jpg' - if not path: - path = '.' - if not name.endswith(('.jpg', '.jpeg', '.png', '.webp')): - name = f'{name}.jpg' - path = get_usable_path(f'{path}{sep}{name}') + path = str(path).rstrip('\\/') if path else '.' + if not path.endswith(('.jpg', '.jpeg', '.png', '.webp')): + if not name: + name = f'{self.title}.jpg' + elif not name.endswith(('.jpg', '.jpeg', '.png', '.webp')): + name = f'{name}.jpg' + path = f'{path}{sep}{name}' + + path = get_usable_path(path) pic_type = path.suffix.lower() pic_type = 'jpeg' if pic_type == '.jpg' else pic_type[1:] diff --git a/DrissionPage/chromium_frame.py b/DrissionPage/chromium_frame.py index 4925910..28319ee 100644 --- a/DrissionPage/chromium_frame.py +++ b/DrissionPage/chromium_frame.py @@ -535,13 +535,16 @@ class ChromiumFrame(ChromiumBase): pic_type = 'jpeg' if as_base64 == 'jpg' else as_base64 else: - if not path: - path = '.' - if not name: - name = f'{self.title}.jpg' - if not name.endswith(('.jpg', '.jpeg', '.png', '.webp')): - name = f'{name}.jpg' - pic_type = name.split('.')[-1] + path = str(path).rstrip('\\/') if path else '.' + if path and path.endswith(('.jpg', '.jpeg', '.png', '.webp')): + pic_type = path.rsplit('.', 1)[-1] + + elif name and name.endswith(('.jpg', '.jpeg', '.png', '.webp')): + pic_type = name.rsplit('.', 1)[-1] + + else: + pic_type = 'jpeg' + if pic_type == 'jpg': pic_type = 'jpeg'