feat(parser)!: Make all selection return selector objects by default

- The strings/Texthandlers are only returned by `get`/`getall`/`extract`/`extract_first`. This makes the type checking/autocompletion experience consistent.
- Removed `css_first` and `xpath_first` since it doesn't make sense to leave them now.
- Made the type hints more accurate in multiple places.
This commit is contained in:
Karim shoair
2026-02-06 02:43:51 +02:00
parent f88502718f
commit aa7a95fb70
3 changed files with 116 additions and 120 deletions
+3
View File
@@ -15,6 +15,9 @@ class SelectorsGeneration:
"""Generate a selector for the current element.
:return: A string of the generated selector.
"""
if self._is_text_node(self._root):
return ""
selectorPath = []
target = self
css = selection.lower() == "css"
+1 -1
View File
@@ -583,7 +583,7 @@ class Convertor:
raise ValueError(f"Unknown extraction type: {extraction_type}")
else:
if main_content_only:
page = cast(Selector, page.css_first("body")) or page
page = cast(Selector, page.css("body").first) or page
pages = [page] if not css_selector else cast(Selectors, page.css(css_selector))
for page in pages: