4.0.3改善get_blob()

This commit is contained in:
g1879 2024-01-18 12:01:02 +08:00
parent 5815474ea9
commit 8ec59c3293
3 changed files with 10 additions and 4 deletions

View File

@ -517,10 +517,10 @@ class ChromiumElement(DrissionElement):
if not result:
return None
if is_blob:
elif is_blob:
return result
if result['base64Encoded'] and base64_to_bytes:
elif result['base64Encoded'] and base64_to_bytes:
from base64 import b64decode
return b64decode(result['content'])
else:

View File

@ -332,7 +332,7 @@ def is_cookie_in_driver(page, cookie):
def get_blob(page, url, base64_to_bytes=True):
if not url.startswith('blob'):
return None
raise TypeError('该链接非blob类型。')
js = """
function fetchData(url) {
return new Promise((resolve, reject) => {
@ -351,7 +351,7 @@ def get_blob(page, url, base64_to_bytes=True):
try:
result = page.run_js(js, url)
except:
return None
raise RuntimeError('无法获取该资源。')
if base64_to_bytes:
from base64 import b64decode
return b64decode(result.split(',', 1)[-1])

View File

@ -1,4 +1,10 @@
# -*- coding:utf-8 -*-
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
"""
from ._elements.chromium_element import ChromiumElement, ShadowRoot
from ._elements.none_element import NoneElement
from ._elements.session_element import SessionElement