diff --git a/DrissionPage/common.py b/DrissionPage/common.py index 1a4352d..44e65a9 100644 --- a/DrissionPage/common.py +++ b/DrissionPage/common.py @@ -120,7 +120,7 @@ def get_loc_from_str(loc: str) -> tuple: 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语句""" tag_name = '' if tag == '*' else f'name()="{tag}" and ' 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)})]" -def _make_search_str(search_str: str): +def _make_search_str(search_str: str) -> str: """将"转义,不知何故不能直接用\"""" parts = search_str.split('"') parts_num = len(parts) @@ -141,7 +141,7 @@ def _make_search_str(search_str: str): return search_str -def translate_loc_to_xpath(loc): +def translate_loc_to_xpath(loc) -> tuple: """把By类型转为xpath或css selector""" loc_by = 'xpath' loc_str = None @@ -185,7 +185,7 @@ def avoid_duplicate_name(folder_path: str, file_name: str) -> str: return file_name -def clean_folder(folder_path: str, ignore: list = None): +def clean_folder(folder_path: str, ignore: list = None) -> None: """清空一个文件夹,除了ignore里的文件和文件夹 :param folder_path: 要清空的文件夹路径 :param ignore: 忽略列表 diff --git a/DrissionPage/driver_element.py b/DrissionPage/driver_element.py index 1933fb5..ea910ed 100644 --- a/DrissionPage/driver_element.py +++ b/DrissionPage/driver_element.py @@ -155,7 +155,7 @@ class DriverElement(DrissionElement): if isinstance(loc_or_str, str): loc_or_str = get_loc_from_str(loc_or_str) elif isinstance(loc_or_str, tuple) and len(loc_or_str) == 2: - loc_or_str = translate_loc_to_xpath(loc_or_str) + pass else: raise ValueError('Argument loc_or_str can only be tuple or str.') diff --git a/DrissionPage/driver_page.py b/DrissionPage/driver_page.py index 26fc0c5..96e7955 100644 --- a/DrissionPage/driver_page.py +++ b/DrissionPage/driver_page.py @@ -110,7 +110,7 @@ class DriverPage(object): if isinstance(loc_or_ele, str): loc_or_ele = get_loc_from_str(loc_or_ele) 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): return loc_or_ele elif isinstance(loc_or_ele, WebElement): diff --git a/DrissionPage/session_page.py b/DrissionPage/session_page.py index 80e99a9..05a443f 100644 --- a/DrissionPage/session_page.py +++ b/DrissionPage/session_page.py @@ -97,16 +97,16 @@ class SessionPage(object): :return: SessionElement对象 """ 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: - loc = translate_loc_to_xpath(loc_or_ele) + loc_or_ele = translate_loc_to_xpath(loc_or_ele) elif isinstance(loc_or_ele, SessionElement): return loc_or_ele elif isinstance(loc_or_ele, Element): return SessionElement(loc_or_ele) else: 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]: """返回页面中所有符合条件的元素 \n