From b938a85c9a68dd957033cd84a8de70ac5512b65c Mon Sep 17 00:00:00 2001 From: g1879 Date: Sat, 30 Mar 2024 22:57:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_base/driver.py | 17 +++++++++-------- DrissionPage/_functions/tools.py | 6 +++--- DrissionPage/_pages/chromium_base.py | 4 ++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/DrissionPage/_base/driver.py b/DrissionPage/_base/driver.py index db243d7..d98bc31 100644 --- a/DrissionPage/_base/driver.py +++ b/DrissionPage/_base/driver.py @@ -229,14 +229,15 @@ class Driver(object): self._ws.close() self._ws = None - try: - while not self.event_queue.empty(): - event = self.event_queue.get_nowait() - function = self.event_handlers.get(event['method']) - if function: - function(**event['params']) - except: - pass + # try: + # while not self.event_queue.empty(): + # event = self.event_queue.get_nowait() + # function = self.event_handlers.get(event['method']) + # if function: + # function(**event['params']) + # sleep(.1) + # except: + # pass self.event_handlers.clear() self.method_results.clear() diff --git a/DrissionPage/_functions/tools.py b/DrissionPage/_functions/tools.py index d89ff05..bb23115 100644 --- a/DrissionPage/_functions/tools.py +++ b/DrissionPage/_functions/tools.py @@ -197,7 +197,8 @@ def raise_error(result, ignore=None): :return: None """ error = result['error'] - if error in ('Cannot find context with specified id', 'Inspected target navigated or closed'): + if error in ('Cannot find context with specified id', 'Inspected target navigated or closed', + 'No frame with given id found'): r = ContextLostError() elif error in ('Could not find node with given id', 'Could not find object with given id', 'No node with given id found', 'Node with given id does not belong to the document', @@ -221,9 +222,8 @@ def raise_error(result, ignore=None): r = RuntimeError(f'你的浏览器可能太旧。\n方法:{result["method"]}\n参数:{result["args"]}') elif result['type'] in ('call_method_error', 'timeout'): from DrissionPage import __version__ - from time import process_time txt = f'\n错误:{result["error"]}\n方法:{result["method"]}\n参数:{result["args"]}\n' \ - f'版本:{__version__}\n运行时间:{process_time()}\n出现这个错误可能意味着程序有bug,请把错误信息和重现方法' \ + f'版本:{__version__}\n出现这个错误可能意味着程序有bug,请把错误信息和重现方法' \ '告知作者,谢谢。\n报告网站:https://gitee.com/g1879/DrissionPage/issues' r = TimeoutError(txt) if result['type'] == 'timeout' else CDPError(txt) else: diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index 0caee3b..0fde9e4 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -168,9 +168,13 @@ class ChromiumBase(BasePage): result = True break + except PageDisconnectedError: + result = False + break except: timeout = end_time - perf_counter() timeout = .5 if timeout <= 0 else timeout + sleep(.1) else: result = False