Skip to content

Commit

Permalink
Use compiled CSS selectors instead of reparsing their XPath
Browse files Browse the repository at this point in the history
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
  • Loading branch information
apasel422 authored and acabal committed Jun 22, 2024
1 parent 63faa54 commit cfaced9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion se/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cfaced9

Please sign in to comment.