diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 02f54a4..d1679b2 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -3,8 +3,9 @@ @Author : g1879 @Contact : g1879@qq.com @Copyright: (c) 2020 by g1879, Inc. All Rights Reserved. -本项目允许个人以源代码形式使用,仅限于学习和合法非盈利使用。 -如未获得版权持有人授权,不得用于商业行为。 + +允许任何人以个人身份使用或分发本项目源代码,但仅限于学习和合法非盈利目的。 +个人或组织如未获得版权持有人授权,不得将本项目以源代码或二进制形式用于商业行为。 使用本项目需满足以下条款,如使用过程中出现违反任意一项条款的情形,授权自动失效。 * 禁止将DrissionPage应用到任何可能违反当地法律规定和道德约束的项目中 diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index 91a0e7d..df085d6 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -1252,7 +1252,13 @@ def parse_js_result(page, ele, result, end_time): r = page._run_cdp('Runtime.getProperties', objectId=result['objectId'], ownProperties=True)['result'] return [parse_js_result(page, ele, result=i['value'], end_time=end_time) for i in r if i['name'].isdigit()] - elif 'objectId' in result: + elif result.get('className') == 'Blob': + data = page._run_cdp('IO.read', + handle=f"blob:{page._run_cdp('IO.resolveBlob', objectId=result['objectId'])['uuid']}")[ + 'data'] + return data + + elif 'objectId' in result and result.get('className') == 'Blob': timeout = end_time - perf_counter() if timeout < 0: return diff --git a/DrissionPage/_functions/cookies.py b/DrissionPage/_functions/cookies.py index 7044b78..e0d8d3e 100644 --- a/DrissionPage/_functions/cookies.py +++ b/DrissionPage/_functions/cookies.py @@ -181,10 +181,8 @@ def format_cookie(cookie): if 'sameSite' in cookie: sameSite = cookie['sameSite'] - if sameSite in (None, False): + if sameSite in (None, False) or sameSite not in ('None', 'Lax', 'Strict', 'no_restriction'): cookie.pop('sameSite') - elif sameSite not in ('None', 'Lax', 'Strict'): - raise ValueError(f'{cookie}\nsameSite字段必须为"None"、"Lax"、"Strict"之一。') if 'priority' in cookie: priority = cookie['priority'] diff --git a/DrissionPage/_units/screencast.py b/DrissionPage/_units/screencast.py index 33d8033..9e930fd 100644 --- a/DrissionPage/_units/screencast.py +++ b/DrissionPage/_units/screencast.py @@ -57,7 +57,7 @@ class Screencast(object): ? "video/webm; codecs=vp9" : "video/webm" mediaRecorder = new MediaRecorder(stream, {mimeType: mime}) - DrissionPage_Screencast_chunks = [] + DrissionPage_Screencast_chunks = []; mediaRecorder.addEventListener('dataavailable', function(e) { DrissionPage_Screencast_blob_ok = false; DrissionPage_Screencast_chunks.push(e.data); @@ -75,6 +75,7 @@ class Screencast(object): print('请手动选择要录制的目标。') self._owner._run_js('var DrissionPage_Screencast_blob;var DrissionPage_Screencast_blob_ok=false;') self._owner._run_js(js) + print('开始录制') def stop(self, video_name=None): if video_name and not video_name.endswith('mp4'): @@ -86,11 +87,12 @@ class Screencast(object): self._owner._run_js('mediaRecorder.stop();', as_expr=True) while not self._owner._run_js('return DrissionPage_Screencast_blob_ok;'): sleep(.05) - blob = self._owner._run_js('return DrissionPage_Screencast_blob;') - uuid = self._owner._run_cdp('IO.resolveBlob', objectId=blob['result']['objectId'])['uuid'] - data = self._owner._run_cdp('IO.read', handle=f'blob:{uuid}')['data'] with open(path, 'wb') as f: - f.write(b64decode(data)) + f.write(b64decode(self._owner._run_js('return DrissionPage_Screencast_blob;'))) + self._owner._run_js('DrissionPage_Screencast_blob_ok = false;' + 'DrissionPage_Screencast_chunks = [];' + 'DrissionPage_Screencast_blob = null', as_expr=True) + print('停止录制') return path if self._mode.startswith('frugal'): @@ -102,6 +104,7 @@ class Screencast(object): sleep(.01) if self._mode.endswith('imgs'): + print('停止录制') return str(Path(self._path).absolute()) if not str(self._path).isascii(): @@ -126,6 +129,7 @@ class Screencast(object): rmtree(self._tmp_path) self._tmp_path = None + print('停止录制') return f'{self._path}{sep}{name}' def set_save_path(self, save_path=None): diff --git a/setup.py b/setup.py index f1c9baf..61bf28b 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( description="Python based web automation tool. It can control the browser and send and receive data packets.", long_description=long_description, long_description_content_type="text/markdown", - license="BSD", + # license="BSD", keywords="DrissionPage", url="https://DrissionPage.cn", include_package_data=True, @@ -33,7 +33,7 @@ setup( "Programming Language :: Python :: 3.6", "Development Status :: 4 - Beta", "Topic :: Utilities", - "License :: OSI Approved :: BSD License", + # "License :: OSI Approved :: BSD License", ], python_requires='>=3.6', entry_points={