From e8f3cf8df34c203a141c779153f9edfcc5124762 Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 1 Nov 2023 23:32:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dget()=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=B2=A1try=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_pages/chromium_base.py | 10 +++++----- DrissionPage/_pages/chromium_frame.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index 2225a44..4a3da72 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -862,13 +862,13 @@ class ChromiumBase(BasePage): for t in range(times + 1): err = None end_time = perf_counter() + timeout - result = self.run_cdp('Page.navigate', url=to_url, _timeout=timeout) - if result.get('error') == 'timeout': + try: + result = self.run_cdp('Page.navigate', url=to_url, _timeout=timeout) + if 'errorText' in result: + err = ConnectionError(result['errorText']) + except TimeoutError: err = TimeoutError('页面连接超时。') - elif 'errorText' in result: - err = ConnectionError(result['errorText']) - if err: sleep(interval) if self._debug or show_errmsg: diff --git a/DrissionPage/_pages/chromium_frame.py b/DrissionPage/_pages/chromium_frame.py index aeba255..ac6f03d 100644 --- a/DrissionPage/_pages/chromium_frame.py +++ b/DrissionPage/_pages/chromium_frame.py @@ -611,13 +611,13 @@ class ChromiumFrame(ChromiumBase): for t in range(times + 1): err = None end_time = perf_counter() + timeout - result = self.driver.call_method('Page.navigate', url=to_url, frameId=self.frame_id, _timeout=timeout) - if result.get('error') == 'timeout': + try: + result = self.run_cdp('Page.navigate', url=to_url, _timeout=timeout) + if 'errorText' in result: + err = ConnectionError(result['errorText']) + except TimeoutError: err = TimeoutError('页面连接超时。') - elif 'errorText' in result: - err = ConnectionError(result['errorText']) - if err: sleep(interval) if self._debug or show_errmsg: