Skip to content

🕷️ The BEST Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev

style(parser): Improve the type hint for `find_by_text` and `find_by_regex`

Karim shoaird00c34ee7f12
diff --git a/scrapling/parser.py b/scrapling/parser.py
index 0edaf94..1ae6db1 100644
--- a/scrapling/parser.py
+++ b/scrapling/parser.py
@@ -1074,6 +1074,26 @@ class Selector(SelectorsGeneration):
return Selectors(map(self.__element_convertor, similar_elements))
+ @overload
+ def find_by_text(
+ self,
+ text: str,
+ first_match: Literal[True] = ...,
+ partial: bool = ...,
+ case_sensitive: bool = ...,
+ clean_match: bool = ...,
+ ) -> "Selector": ...
+
+ @overload
+ def find_by_text(
+ self,
+ text: str,
+ first_match: Literal[False],
+ partial: bool = ...,
+ case_sensitive: bool = ...,
+ clean_match: bool = ...,
+ ) -> "Selectors": ...
+
def find_by_text(
self,
text: str,
@@ -1122,6 +1142,24 @@ class Selector(SelectorsGeneration):
return results[0]
return results
+ @overload
+ def find_by_regex(
+ self,
+ query: str | Pattern[str],
+ first_match: Literal[True] = ...,
+ case_sensitive: bool = ...,
+ clean_match: bool = ...,
+ ) -> "Selector": ...
+
+ @overload
+ def find_by_regex(
+ self,
+ query: str | Pattern[str],
+ first_match: Literal[False],
+ case_sensitive: bool = ...,
+ clean_match: bool = ...,
+ ) -> "Selectors": ...
+
def find_by_regex(
self,
query: str | Pattern[str],