mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
4.0.3改善get_blob()
This commit is contained in:
parent
5815474ea9
commit
8ec59c3293
@ -517,10 +517,10 @@ class ChromiumElement(DrissionElement):
|
|||||||
if not result:
|
if not result:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if is_blob:
|
elif is_blob:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
if result['base64Encoded'] and base64_to_bytes:
|
elif result['base64Encoded'] and base64_to_bytes:
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
return b64decode(result['content'])
|
return b64decode(result['content'])
|
||||||
else:
|
else:
|
||||||
|
@ -332,7 +332,7 @@ def is_cookie_in_driver(page, cookie):
|
|||||||
|
|
||||||
def get_blob(page, url, base64_to_bytes=True):
|
def get_blob(page, url, base64_to_bytes=True):
|
||||||
if not url.startswith('blob'):
|
if not url.startswith('blob'):
|
||||||
return None
|
raise TypeError('该链接非blob类型。')
|
||||||
js = """
|
js = """
|
||||||
function fetchData(url) {
|
function fetchData(url) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -351,7 +351,7 @@ def get_blob(page, url, base64_to_bytes=True):
|
|||||||
try:
|
try:
|
||||||
result = page.run_js(js, url)
|
result = page.run_js(js, url)
|
||||||
except:
|
except:
|
||||||
return None
|
raise RuntimeError('无法获取该资源。')
|
||||||
if base64_to_bytes:
|
if base64_to_bytes:
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
return b64decode(result.split(',', 1)[-1])
|
return b64decode(result.split(',', 1)[-1])
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
# -*- coding:utf-8 -*-
|
# -*- 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.chromium_element import ChromiumElement, ShadowRoot
|
||||||
from ._elements.none_element import NoneElement
|
from ._elements.none_element import NoneElement
|
||||||
from ._elements.session_element import SessionElement
|
from ._elements.session_element import SessionElement
|
||||||
|
Loading…
x
Reference in New Issue
Block a user