From 873cf384031fde0f73d2e2a042327e73e7040d71 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Fri, 21 Jun 2024 11:00:21 -0400 Subject: [PATCH] Use compiled CSS selectors instead of reparsing their XPath https://lxml.de/cssselect.html#the-cssselector-class These selectors can only return elements, so there is no need to go through the result processing performed in the xpath method. Fixes #711 --- se/easy_xml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/se/easy_xml.py b/se/easy_xml.py index 01b2500f..3e19ffec 100644 --- a/se/easy_xml.py +++ b/se/easy_xml.py @@ -87,7 +87,7 @@ def css_select(self, selector: str): sel = cssselect.CSSSelector(selector, translator="xhtml", namespaces=self.namespaces) CSS_SELECTOR_CACHE[selector] = sel - return self.xpath(sel.path) + return [EasyXmlElement(element, self.namespaces) for element in sel(self.etree)] except parser.SelectorSyntaxError as ex: raise se.InvalidCssException(f"Invalid selector: [css]{selector}[/]") from ex