Karim shoair commited on
Commit
1003d98
·
1 Parent(s): 51d65e1

refactor(parser/find_all): about ~95% speed increase

Browse files
Files changed (1) hide show
  1. scrapling/parser.py +3 -11
scrapling/parser.py CHANGED
@@ -593,14 +593,6 @@ class Adaptor(SelectorsGeneration):
593
  tags, patterns = set(), set()
594
  results, functions, selectors = Adaptors([]), [], []
595
 
596
- def _search_tree(element: Adaptor, filter_function: Callable) -> None:
597
- """Collect element if it fulfills passed function otherwise, traverse the children tree and iterate"""
598
- if filter_function(element):
599
- results.append(element)
600
-
601
- for branch in element.children:
602
- _search_tree(branch, filter_function)
603
-
604
  # Brace yourself for a wonderful journey!
605
  for arg in args:
606
  if type(arg) is str:
@@ -661,9 +653,9 @@ class Adaptor(SelectorsGeneration):
661
  for pattern in patterns:
662
  results.extend(self.find_by_regex(pattern, first_match=False))
663
 
664
- for result in (results or [self]):
665
- for function in functions:
666
- _search_tree(result, function)
667
 
668
  return results
669
 
 
593
  tags, patterns = set(), set()
594
  results, functions, selectors = Adaptors([]), [], []
595
 
 
 
 
 
 
 
 
 
596
  # Brace yourself for a wonderful journey!
597
  for arg in args:
598
  if type(arg) is str:
 
653
  for pattern in patterns:
654
  results.extend(self.find_by_regex(pattern, first_match=False))
655
 
656
+ # Collect element if it fulfills passed function otherwise
657
+ for function in functions:
658
+ results.extend((results or self.below_elements).filter(function))
659
 
660
  return results
661