From 8daf63b469f27843f772d515f2a0b3d79db4585b Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 8 Feb 2023 18:53:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=82=E5=9F=9Fiframe?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84500=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_frame.py | 12 +++++++++++- DrissionPage/chromium_frame.pyi | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/DrissionPage/chromium_frame.py b/DrissionPage/chromium_frame.py index 517b4ff..9b6e1cd 100644 --- a/DrissionPage/chromium_frame.py +++ b/DrissionPage/chromium_frame.py @@ -48,7 +48,16 @@ class ChromiumFrame(ChromiumBase): self._timeouts = self.page.timeouts self._page_load_strategy = self.page.page_load_strategy + def _init_page(self, tab_id=None): + """避免出现服务器500错误 + :param tab_id: 要跳转到的标签页id + :return: None + """ + self._control_session.get(f'http://{self.address}/json') + super()._init_page(tab_id) + def _reload(self): + """重新获取document""" self._frame_ele = ChromiumElement(self.page, backend_id=self._backend_id) node = self.page.run_cdp('DOM.describeNode', nodeId=self._frame_ele.node_id, not_change=True)['node'] @@ -64,6 +73,7 @@ class ChromiumFrame(ChromiumBase): self.doc_ele = ChromiumElement(self, obj_id=obj_id) def _check_ok(self): + """""" if self._tab_obj._stopped.is_set(): self._reload() @@ -71,7 +81,7 @@ class ChromiumFrame(ChromiumBase): self._tab_obj.DOM.describeNode(nodeId=self.node_id) except Exception: self._reload() - sleep(2) + # sleep(2) def _get_new_document(self): """刷新cdp使用的document数据""" diff --git a/DrissionPage/chromium_frame.pyi b/DrissionPage/chromium_frame.pyi index 297f96e..8aa65e8 100644 --- a/DrissionPage/chromium_frame.pyi +++ b/DrissionPage/chromium_frame.pyi @@ -30,6 +30,8 @@ class ChromiumFrame(ChromiumBase): def _set_options(self) -> None: ... + def _init_page(self, tab_id: str = None) -> None: ... + def _reload(self) -> None: ... def _check_ok(self) -> None: ...