From 8ec59c32936f129fc366851e3336ba7e906c5d1b Mon Sep 17 00:00:00 2001 From: g1879 Date: Thu, 18 Jan 2024 12:01:02 +0800 Subject: [PATCH] =?UTF-8?q?4.0.3=E6=94=B9=E5=96=84get=5Fblob()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_elements/chromium_element.py | 4 ++-- DrissionPage/_functions/web.py | 4 ++-- DrissionPage/items.py | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index 8a20a44..ca373e1 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -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: diff --git a/DrissionPage/_functions/web.py b/DrissionPage/_functions/web.py index f3a458e..f731162 100644 --- a/DrissionPage/_functions/web.py +++ b/DrissionPage/_functions/web.py @@ -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]) diff --git a/DrissionPage/items.py b/DrissionPage/items.py index fea5bb6..0715e91 100644 --- a/DrissionPage/items.py +++ b/DrissionPage/items.py @@ -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