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'