Check if the element should be skipped.
(elem)
| 47 | seen_texts = set() # To avoid duplicates |
| 48 | |
| 49 | def should_skip_element(elem) -> bool: |
| 50 | """Check if the element should be skipped.""" |
| 51 | # Skip script and style tags |
| 52 | if elem.tag in ['{http://www.w3.org/1999/xhtml}script', |
| 53 | '{http://www.w3.org/1999/xhtml}style']: |
| 54 | return True |
| 55 | # Skip empty elements or elements with only whitespace |
| 56 | if not any(text.strip() for text in elem.itertext()): |
| 57 | return True |
| 58 | return False |
| 59 | |
| 60 | def process_element(elem, depth=0): |
| 61 | """Process an element and its children recursively.""" |