修复几个小问题

This commit is contained in:
g1879 2023-11-20 14:59:14 +08:00
parent e52d14a962
commit b3d1c54980
3 changed files with 8 additions and 7 deletions

View File

@ -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拼接并返回

View File

@ -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: ...

View File

@ -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: