优化逻辑

This commit is contained in:
g1879 2024-07-08 23:49:24 +08:00
parent 5feb58bc65
commit 73b6f1c475
2 changed files with 14 additions and 7 deletions

View File

@ -78,23 +78,28 @@ def get_ele_txt(e):
if re_str and re_str[-1] == '\n':
re_str.pop()
re_str = [i if i is not True else '\n' for i in re_str]
l = len(re_str)
if l > 1:
r = []
for i in range(0, l - 1, 2):
for i in range(l - 1):
i1 = re_str[i]
i2 = re_str[i + 1]
if i1 is True:
r.append('\n')
continue
if i2 is True:
r.append(i1)
continue
if i1.endswith(' ') and i2.startswith(' '):
i1 = i1[:-1]
r.append(i1)
r.append(i2)
r.append('\n' if re_str[-1] is True else re_str[-1])
re_str = ''.join(r)
elif not l:
re_str = ''
else:
re_str = re_str[0]
re_str = re_str[0] if re_str[0] is not True else '\n'
return format_html(re_str.strip())

View File

@ -19,6 +19,7 @@ from .._elements.chromium_element import run_js, make_chromium_eles
from .._elements.none_element import NoneElement
from .._elements.session_element import make_session_ele
from .._functions.cookies import CookiesList
from .._functions.elements import SessionElementsList
from .._functions.locator import get_loc, is_loc
from .._functions.settings import Settings
from .._functions.tools import raise_error
@ -547,8 +548,8 @@ class ChromiumBase(BasePage):
:param index: 获取第几个从1开始可传入负数获取倒数第几个
:return: SessionElement对象或属性文本
"""
if locator:
self.wait.eles_loaded(locator)
if locator and not self.wait.eles_loaded(locator):
return NoneElement(self, method='s_ele()', args={'locator': locator, 'index': index})
return make_session_ele(self, locator, index=index, method='s_ele()')
def s_eles(self, locator):
@ -556,7 +557,8 @@ class ChromiumBase(BasePage):
:param locator: 元素的定位信息可以是loc元组或查询字符串
:return: SessionElement对象组成的列表
"""
self.wait.eles_loaded(locator)
if not self.wait.eles_loaded(locator):
return SessionElementsList()
return make_session_ele(self, locator, index=None)
def _find_elements(self, locator, timeout=None, index=1, relative=False, raise_err=None):