From c1f3f51a142b11cd28fc42c559b9f288fe5b69d2 Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 21 Oct 2020 16:05:04 +0800 Subject: [PATCH] =?UTF-8?q?texts=E5=B1=9E=E6=80=A7=EF=BC=8C=E6=9C=AA?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/driver_element.py | 8 +++++--- DrissionPage/session_element.py | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/DrissionPage/driver_element.py b/DrissionPage/driver_element.py index 03934f5..152fb7d 100644 --- a/DrissionPage/driver_element.py +++ b/DrissionPage/driver_element.py @@ -61,9 +61,11 @@ class DriverElement(DrissionElement): """返回元素内所有文本""" return unescape(self.attr('innerText')).replace('\xa0', ' ') - @property - def texts(self) -> List[str]: + def texts(self, text_node_only: bool = False) -> List[str]: """返回元素内文本节点列表""" + s = '' if text_node_only else '''else if(childs[i].nodeType === Node.ELEMENT_NODE){ + texts.push(childs[i].innerText) + }''' js = ''' function e(el) { if (!(el instanceof Element)) return; @@ -73,7 +75,7 @@ class DriverElement(DrissionElement): for(var i = 0; i List[str]: + def texts(self, text_node_only: bool = False) -> List[str]: # TODO: 待补充 return []