From b3d1c54980f365a87e4ee8bd7cf7714c0cd89490 Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 20 Nov 2023 14:59:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=87=A0=E4=B8=AA=E5=B0=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_commons/web.py | 9 +++++---- DrissionPage/_commons/web.pyi | 2 +- DrissionPage/_units/network_listener.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/DrissionPage/_commons/web.py b/DrissionPage/_commons/web.py index 9d9c7b5..c2598c6 100644 --- a/DrissionPage/_commons/web.py +++ b/DrissionPage/_commons/web.py @@ -112,16 +112,16 @@ def offset_scroll(ele, offset_x, offset_y): :param offset_y: 偏移量y :return: 视口中的坐标 """ - loc_x, loc_y = ele.location - cp_x, cp_y = ele.locations.click_point + loc_x, loc_y = ele.rect.location + cp_x, cp_y = ele.rect.click_point lx = loc_x + offset_x if offset_x else cp_x ly = loc_y + offset_y if offset_y else cp_y if not location_in_viewport(ele.page, lx, ly): clientWidth = ele.page.run_js('return document.body.clientWidth;') clientHeight = ele.page.run_js('return document.body.clientHeight;') ele.page.scroll.to_location(lx - clientWidth // 2, ly - clientHeight // 2) - cl_x, cl_y = ele.locations.viewport_location - ccp_x, ccp_y = ele.locations.viewport_click_point + cl_x, cl_y = ele.rect.viewport_location + ccp_x, ccp_y = ele.rect.viewport_click_point cx = cl_x + offset_x if offset_x else ccp_x cy = cl_y + offset_y if offset_y else ccp_y return cx, cy @@ -136,6 +136,7 @@ def make_absolute_link(link, page=None): if not link: return link + link = link.strip() parsed = urlparse(link)._asdict() # 是相对路径,与页面url拼接并返回 diff --git a/DrissionPage/_commons/web.pyi b/DrissionPage/_commons/web.pyi index d6b9dc2..7bf9a5f 100644 --- a/DrissionPage/_commons/web.pyi +++ b/DrissionPage/_commons/web.pyi @@ -26,7 +26,7 @@ def location_in_viewport(page: ChromiumBase, loc_x: float, loc_y: float) -> bool def offset_scroll(ele: ChromiumElement, offset_x: float, offset_y: float) -> tuple: ... -def make_absolute_link(link, page: BasePage = None) -> str: ... +def make_absolute_link(link: str, page: BasePage = None) -> str: ... def is_js_func(func: str) -> bool: ... diff --git a/DrissionPage/_units/network_listener.py b/DrissionPage/_units/network_listener.py index 7ab0df9..a0bf2c0 100644 --- a/DrissionPage/_units/network_listener.py +++ b/DrissionPage/_units/network_listener.py @@ -190,7 +190,7 @@ class NetworkListener(object): def _requestWillBeSent(self, **kwargs): """接收到请求时的回调函数""" - if kwargs['frameId'] != self._page._frame_id: + if kwargs.get('frameId', self._page._frame_id) != self._page._frame_id: return p = None if not self._targets: @@ -222,7 +222,7 @@ class NetworkListener(object): def _response_received(self, **kwargs): """接收到返回信息时处理方法""" - if kwargs['frameId'] != self._page._frame_id: + if kwargs.get('frameId', self._page._frame_id) != self._page._frame_id: return request = self._request_ids.get(kwargs['requestId'], None) if request: