From e56995dcf0449a52d1ca4140a22f3f49902be584 Mon Sep 17 00:00:00 2001 From: g1879 Date: Fri, 5 Jan 2024 00:25:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83=5Fget=5Fdocument()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_pages/chromium_base.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index 3b66a76..7581c89 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -151,29 +151,31 @@ class ChromiumBase(BasePage): """ if self._is_reading: return - timeout = timeout if timeout >= .5 else .5 self._is_reading = True + timeout = timeout if timeout >= .5 else .5 end_time = perf_counter() + timeout while perf_counter() < end_time: try: b_id = self.run_cdp('DOM.getDocument', _timeout=timeout)['root']['backendNodeId'] timeout = end_time - perf_counter() - timeout = .5 if timeout < 0 else timeout - self._root_id = self.run_cdp('DOM.resolveNode', - backendNodeId=b_id, _timeout=timeout)['object']['objectId'] - r = self.run_cdp('Page.getFrameTree') - for i in findall(r"'id': '(.*?)'", str(r)): - self.browser._frames[i] = self.tab_id + timeout = .5 if timeout <= 0 else timeout + self._root_id = self.run_cdp('DOM.resolveNode', backendNodeId=b_id, + _timeout=timeout)['object']['objectId'] result = True break except: timeout = end_time - perf_counter() - timeout = .5 if timeout < 0 else timeout + timeout = .5 if timeout <= 0 else timeout else: result = False + if result: + r = self.run_cdp('Page.getFrameTree') + for i in findall(r"'id': '(.*?)'", str(r)): + self.browser._frames[i] = self.tab_id + self._is_loading = False self._is_reading = False return result