1
0
mirror of https://gitee.com/g1879/DrissionPage.git synced 2024-12-10 04:00:23 +08:00
This commit is contained in:
g1879 2020-08-08 01:05:19 +08:00
parent ddbe20f7a8
commit 1c9bc8dd24
4 changed files with 9 additions and 9 deletions

@ -120,7 +120,7 @@ def get_loc_from_str(loc: str) -> tuple:
return loc_by, loc_str return loc_by, loc_str
def _make_xpath_str(tag: str, arg: str, val: str, mode: str = 'fuzzy'): def _make_xpath_str(tag: str, arg: str, val: str, mode: str = 'fuzzy') -> str:
"""生成xpath语句""" """生成xpath语句"""
tag_name = '' if tag == '*' else f'name()="{tag}" and ' tag_name = '' if tag == '*' else f'name()="{tag}" and '
if mode == 'exact': if mode == 'exact':
@ -129,7 +129,7 @@ def _make_xpath_str(tag: str, arg: str, val: str, mode: str = 'fuzzy'):
return f"//*[{tag_name}contains({arg},{_make_search_str(val)})]" return f"//*[{tag_name}contains({arg},{_make_search_str(val)})]"
def _make_search_str(search_str: str): def _make_search_str(search_str: str) -> str:
""""转义,不知何故不能直接用\"""" """"转义,不知何故不能直接用\""""
parts = search_str.split('"') parts = search_str.split('"')
parts_num = len(parts) parts_num = len(parts)
@ -141,7 +141,7 @@ def _make_search_str(search_str: str):
return search_str return search_str
def translate_loc_to_xpath(loc): def translate_loc_to_xpath(loc) -> tuple:
"""把By类型转为xpath或css selector""" """把By类型转为xpath或css selector"""
loc_by = 'xpath' loc_by = 'xpath'
loc_str = None loc_str = None
@ -185,7 +185,7 @@ def avoid_duplicate_name(folder_path: str, file_name: str) -> str:
return file_name return file_name
def clean_folder(folder_path: str, ignore: list = None): def clean_folder(folder_path: str, ignore: list = None) -> None:
"""清空一个文件夹除了ignore里的文件和文件夹 """清空一个文件夹除了ignore里的文件和文件夹
:param folder_path: 要清空的文件夹路径 :param folder_path: 要清空的文件夹路径
:param ignore: 忽略列表 :param ignore: 忽略列表

@ -155,7 +155,7 @@ class DriverElement(DrissionElement):
if isinstance(loc_or_str, str): if isinstance(loc_or_str, str):
loc_or_str = get_loc_from_str(loc_or_str) loc_or_str = get_loc_from_str(loc_or_str)
elif isinstance(loc_or_str, tuple) and len(loc_or_str) == 2: elif isinstance(loc_or_str, tuple) and len(loc_or_str) == 2:
loc_or_str = translate_loc_to_xpath(loc_or_str) pass
else: else:
raise ValueError('Argument loc_or_str can only be tuple or str.') raise ValueError('Argument loc_or_str can only be tuple or str.')

@ -110,7 +110,7 @@ class DriverPage(object):
if isinstance(loc_or_ele, str): if isinstance(loc_or_ele, str):
loc_or_ele = get_loc_from_str(loc_or_ele) loc_or_ele = get_loc_from_str(loc_or_ele)
elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2: elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2:
loc_or_ele = translate_loc_to_xpath(loc_or_ele) pass
elif isinstance(loc_or_ele, DriverElement): elif isinstance(loc_or_ele, DriverElement):
return loc_or_ele return loc_or_ele
elif isinstance(loc_or_ele, WebElement): elif isinstance(loc_or_ele, WebElement):

@ -97,16 +97,16 @@ class SessionPage(object):
:return: SessionElement对象 :return: SessionElement对象
""" """
if isinstance(loc_or_ele, str): if isinstance(loc_or_ele, str):
loc = get_loc_from_str(loc_or_ele) loc_or_ele = get_loc_from_str(loc_or_ele)
elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2: elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2:
loc = translate_loc_to_xpath(loc_or_ele) loc_or_ele = translate_loc_to_xpath(loc_or_ele)
elif isinstance(loc_or_ele, SessionElement): elif isinstance(loc_or_ele, SessionElement):
return loc_or_ele return loc_or_ele
elif isinstance(loc_or_ele, Element): elif isinstance(loc_or_ele, Element):
return SessionElement(loc_or_ele) return SessionElement(loc_or_ele)
else: else:
raise ValueError('Argument loc_or_str can only be tuple, str, SessionElement, Element.') raise ValueError('Argument loc_or_str can only be tuple, str, SessionElement, Element.')
return execute_session_find(self.response.html, loc, mode, show_errmsg) return execute_session_find(self.response.html, loc_or_ele, mode, show_errmsg)
def eles(self, loc_or_str: Union[tuple, str], show_errmsg: bool = False) -> List[SessionElement]: def eles(self, loc_or_str: Union[tuple, str], show_errmsg: bool = False) -> List[SessionElement]:
"""返回页面中所有符合条件的元素 \n """返回页面中所有符合条件的元素 \n