From 01a930b7403106a936f8ce51559909299d298b65 Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 9 Aug 2023 11:50:49 +0800 Subject: [PATCH] =?UTF-8?q?get=5Fsrc()=E6=96=B9=E6=B3=95=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?base64=5Fto=5Fbytes=E5=8F=82=E6=95=B0=EF=BC=9B=E4=BD=BF?= =?UTF-8?q?=E7=94=A81.0.0=E7=89=88DownloadKit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_element.py | 12 ++++++++---- DrissionPage/chromium_element.pyi | 2 +- requirements.txt | 2 +- setup.py | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/DrissionPage/chromium_element.py b/DrissionPage/chromium_element.py index 9e56a8e..3750000 100644 --- a/DrissionPage/chromium_element.py +++ b/DrissionPage/chromium_element.py @@ -439,9 +439,10 @@ class ChromiumElement(DrissionElement): js = f'return window.getComputedStyle(this{pseudo_ele}).getPropertyValue("{style}");' return self.run_js(js) - def get_src(self, timeout=None): - """返回元素src资源,base64的会转为bytes返回,其它返回str + def get_src(self, timeout=None, base64_to_bytes=True): + """返回元素src资源,base64的可转为bytes返回,其它返回str :param timeout: 等待资源加载的超时时间 + :param base64_to_bytes: 为True时,如果是base64数据,转换为bytes格式 :return: 资源内容 """ timeout = self.page.timeout if timeout is None else timeout @@ -474,8 +475,11 @@ class ChromiumElement(DrissionElement): return None if result['base64Encoded']: - from base64 import b64decode - data = b64decode(result['content']) + if base64_to_bytes: + from base64 import b64decode + data = b64decode(result['content']) + else: + data = result['content'] else: data = result['content'] return data diff --git a/DrissionPage/chromium_element.pyi b/DrissionPage/chromium_element.pyi index 3b5dfe1..da4654f 100644 --- a/DrissionPage/chromium_element.pyi +++ b/DrissionPage/chromium_element.pyi @@ -178,7 +178,7 @@ class ChromiumElement(DrissionElement): def style(self, style: str, pseudo_ele: str = '') -> str: ... - def get_src(self, timeout: float = None) -> Union[bytes, str, None]: ... + def get_src(self, timeout: float = None, base64_to_bytes: bool = True) -> Union[bytes, str, None]: ... def save(self, path: [str, bool] = None, rename: str = None, timeout: float = None) -> None: ... diff --git a/requirements.txt b/requirements.txt index d04ff8e..4e712ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ requests lxml cssselect -DownloadKit>=0.5.3 +DownloadKit>=1.0.0 FlowViewer>=0.3.0 websocket-client click diff --git a/setup.py b/setup.py index d621cb6..ab09e66 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh: setup( name="DrissionPage", - version="3.2.30", + version="3.3.0", author="g1879", author_email="g1879@qq.com", description="Python based web automation tool. It can control the browser and send and receive data packets.", @@ -22,7 +22,7 @@ setup( 'lxml', 'requests', 'cssselect', - 'DownloadKit>=0.5.3', + 'DownloadKit>=1.0.0', 'FlowViewer>=0.3.0', 'websocket-client', 'click',