From 646586a0aa81ba4a76b3f5afbef02d4e72f33d77 Mon Sep 17 00:00:00 2001 From: g1879 Date: Sun, 15 Nov 2020 19:23:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlxml=E7=9A=84tostring?= =?UTF-8?q?=E8=8E=B7=E5=8F=96html=E6=97=B6=E4=BC=9A=E6=8A=8A=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E5=90=8E=E9=9D=A2=E7=9A=84=E6=96=87=E6=9C=AC=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=B8=A6=E4=B8=8A=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/session_element.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DrissionPage/session_element.py b/DrissionPage/session_element.py index 355deb8..a2cb090 100644 --- a/DrissionPage/session_element.py +++ b/DrissionPage/session_element.py @@ -37,7 +37,9 @@ class SessionElement(DrissionElement): @property def html(self) -> str: """返回元素outerHTML文本""" - return format_html(tostring(self._inner_ele, method="html").decode()) + # tostring()会把跟紧元素的文本节点也带上,因此要去掉 + html = format_html(tostring(self._inner_ele, method="html").decode()) + return html[:html.rfind('>') + 1] @property def inner_html(self) -> str: