From 2dc9d9c86c83c08dca8411517f4e2ba32691c1df Mon Sep 17 00:00:00 2001 From: Battleplus <3559424769@qq.com> Date: Mon, 24 Aug 2026 13:07:57 +0800 Subject: [PATCH] fix(filter): respect preserve_tags in excluded_tags removal (#2125) _prune_tree already respects preserve_tags via _is_preserved(), but _remove_unwanted_tags runs first and decomposes all excluded tags (nav, footer, header, aside, ...) unconditionally. So PruningContentFilter(preserve_tags=["aside"]) was silently ignored. Add preserve_tags check in _remove_unwanted_tags to skip elements whose tag is in the preserve whitelist. Closes #2125 --- crawl4ai/content_filter_strategy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crawl4ai/content_filter_strategy.py b/crawl4ai/content_filter_strategy.py index ab99a793c..1144ac041 100644 --- a/crawl4ai/content_filter_strategy.py +++ b/crawl4ai/content_filter_strategy.py @@ -683,9 +683,14 @@ def _remove_comments(self, soup): element.extract() def _remove_unwanted_tags(self, soup): - """Removes unwanted tags""" + """Removes unwanted tags, respecting preserve_tags whitelist.""" for tag in self.excluded_tags: for element in soup.find_all(tag): + # Skip elements that match preserve_tags — they should be kept + # even if the tag is in excluded_tags (e.g.,