From 314e7d1989e8aa34acb554bb7f739de8f2f20eca Mon Sep 17 00:00:00 2001 From: g1879 Date: Fri, 25 Nov 2022 23:05:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=B7=E6=96=B0=E3=80=81?= =?UTF-8?q?=E5=89=8D=E8=BF=9B=E3=80=81=E5=90=8E=E9=80=80=E6=97=B6=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_base.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index 56b0247..bd3d826 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -144,7 +144,6 @@ class ChromiumBase(BasePage): """返回用于控制浏览器的Tab对象,会先等待页面加载完毕""" while self._is_loading: sleep(.1) - self._wait_loading() return self._tab_obj @property @@ -407,20 +406,34 @@ class ChromiumBase(BasePage): :return: None """ self._driver.Page.reload(ignoreCache=ignore_cache) + self._get_document() def forward(self, steps: int = 1) -> None: """在浏览历史中前进若干步 \n :param steps: 前进步数 :return: None """ - self.run_script(f'window.history.go({steps});', as_expr=True) + self._forward_or_back(steps) def back(self, steps: int = 1) -> None: """在浏览历史中后退若干步 \n :param steps: 后退步数 :return: None """ - self.run_script(f'window.history.go({-steps});', as_expr=True) + self._forward_or_back(-steps) + + def _forward_or_back(self, steps: int) -> None: + """执行浏览器前进或后退 + :param steps: 步数 + :return: None + """ + self.run_script(f'window.history.go({steps});', as_expr=True) + while True: + try: + self._get_document() + break + except Exception: + sleep(.1) def stop_loading(self) -> None: """页面停止加载""" @@ -732,4 +745,4 @@ class Timeout(object): @property def implicit(self): - return self.page.timeout \ No newline at end of file + return self.page.timeout