get_src()方法增加base64_to_bytes参数;使用1.0.0版DownloadKit

This commit is contained in:
g1879 2023-08-09 11:50:49 +08:00
parent dea41ab0dc
commit 01a930b740
4 changed files with 12 additions and 8 deletions

View File

@ -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

View File

@ -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: ...

View File

@ -1,7 +1,7 @@
requests
lxml
cssselect
DownloadKit>=0.5.3
DownloadKit>=1.0.0
FlowViewer>=0.3.0
websocket-client
click

View File

@ -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',