diff --git a/DrissionPage/driver_element.py b/DrissionPage/driver_element.py index 1090ac4..00ce8c1 100644 --- a/DrissionPage/driver_element.py +++ b/DrissionPage/driver_element.py @@ -591,11 +591,12 @@ class ElementsByXpath(object): if self.mode == 'single': try: e = get_nodes(the_node, xpath_txt=self.xpath, type_txt='9') - return DriverElement(e, self.timeout) if isinstance(e, WebElement) else e + return DriverElement(e, self.timeout) if isinstance(e, WebElement) else unescape(e).replace('\xa0', ' ') except JavascriptException: # 找不到目标时 return None elif self.mode == 'all': e = get_nodes(the_node, xpath_txt=self.xpath) e = filter(lambda x: x != '\n', e) # 去除元素间换行符 + e = map(lambda x: unescape(x).replace('\xa0', ' ') if isinstance(x, str) else x, e) # 替换空格 return list(map(lambda x: DriverElement(x, self.timeout) if isinstance(x, WebElement) else x, e)) diff --git a/DrissionPage/session_element.py b/DrissionPage/session_element.py index 8c4b8ec..4a5ee80 100644 --- a/DrissionPage/session_element.py +++ b/DrissionPage/session_element.py @@ -37,11 +37,10 @@ class SessionElement(DrissionElement): return unescape(self._inner_ele.text).replace('\xa0', ' ') def texts(self, text_node_only: bool = False) -> List[str]: - nodes = self.eles('xpath:./*/node()') if text_node_only: - return [x for x in nodes if isinstance(x, str)] + return self.eles('xpath:./*/text()') else: - return [x if isinstance(x, str) else x.text for x in nodes] + return [x if isinstance(x, str) else x.text for x in self.eles('xpath:./*/node()')] @property def html(self) -> str: @@ -274,9 +273,10 @@ def execute_session_find(page_or_ele: BaseParser, if mode == 'single': ele = ele[0] if ele else None - return SessionElement(ele) if isinstance(ele, Element) else ele + return SessionElement(ele) if isinstance(ele, Element) else unescape(ele).replace('\xa0', ' ') elif mode == 'all': ele = filter(lambda x: x != '\n', ele) # 去除元素间换行符 + ele = map(lambda x: unescape(x).replace('\xa0', ' ') if isinstance(x, str) else x, ele) # 替换空格 return [SessionElement(e) if isinstance(e, Element) else e for e in ele] except: if show_errmsg: