defuddle 如何精准剔除站点 Logo 而不误伤正文——selectors--logo-substring-wrapper 测试样本全解析
后端【免费下载链接】defuddleGet the main content of any page as Markdown.项目地址https://gitcode.com/gh_mirrors/de/defuddle点击查看免费下载在网页正文提取场景中「Logo」是最常见也最容易误判的页面噪声几乎所有站点都会把站标放在header里而部分站点又习惯用logo作为 class 命名的一部分。当正文容器的 class 恰好也包含logo子串时例如a-content--logo-end一个粗糙的子串匹配规则会把整篇正文误删。本文以 defuddle 仓库中的测试样本 selectors--logo-substring-wrapper.html 及其期望输出 selectors--logo-substring-wrapper.md 为切入点逐行拆解 defuddle 的选择器清理机制精确选择器与部分选择器如何分工、logo词边界正则如何做到该删的删、该留的留以及这一行为如何被 fixture 测试体系固化下来。读完本文你将掌握 defuddle 选择器规则的判定边界也能学会如何为自己的站点排查正文被误删这类问题。测试样本要验证什么一个名字里藏着 logo的正文容器先看这个 fixture 对应的原始 HTMLtests/fixtures/selectors--logo-substring-wrapper.html它的结构非常典型!DOCTYPE html html head titleCity Approves Transit Expansion - Example Daily/title meta nameauthor contentJordan Blake /head body header classsite-header div classlogoa href/img src/img/logo.svg altExample Daily/a/div /header main classpage-main article classarticle-body h1City Approves Transit Expansion/h1 div classkey-points pThe council approved three new transit lines .../p !-- 若干关键要点段落 -- /div div classa-content a-content--logo-end div classbody-copy pThe vote clears the way for construction to begin .../p !-- 正文主体段落 -- /div /div /article /main /body /html页面上存在两个敏感目标header classsite-header内的div classlogo——这是真正的站点 Logo 容器必须被剔除div classa-content a-content--logo-end——这是正文的外层包装容器它的 class 里含有logo子串a-content--logo-end中的logo但它承载的是文章主体绝不能因为子串匹配被误删。测试文件名selectors--logo-substring-wrapper正是对这一场景的精确概括logo-substringlogo 子串与 wrapper正文包装层。期望输出 selectors--logo-substring-wrapper.md 证明了 defuddle 的正确行为Logo 容器消失而正文完好无损地保留下来{ title: City Approves Transit Expansion, author: Jordan Blake, site: Example Daily, published: }The council approved three new transit lines on a nine-to-four vote after a hearing that ran past midnight, ending a debate that has occupied the chamber in one form or another for the better part of two decades without ever reaching a binding decision.Bonds issued by the transit authority will cover roughly two thirds of the projected cost, with the remainder drawn from a state matching fund that lawmakers renewed earlier this year over the objections of the rural caucus, which wanted the money spent on highway resurfacing instead.Two members who voted against the measure have asked for an independent audit of the ridership projections before any bonds are issued, and a third said she would support the audit even though she voted in favor of the expansion on the merits of the eastern alignment.Construction on the first line is scheduled to begin in March and to reach the eastern terminus in four years, though the authority has cautioned that the schedule assumes it can acquire the last right-of-way parcels without going to court over the price of two industrial lots.The county commission still has to ratify the cost-sharing agreement, a step the mayors office describes as a formality but that at least two commissioners have said they intend to use as leverage for a station stop that the current alignment leaves out entirely.The vote clears the way for construction to begin next spring on lines that will connect the eastern suburbs to the downtown core for the first time since the original system opened, when the eastern edge of the built-up area stopped several miles short of where it stands today.Officials estimate that the first of the three lines will carry passengers within four years of groundbreaking, assuming the environmental review now underway concludes on schedule and the authority is able to acquire the last of the right-of-way parcels without resorting to condemnation proceedings.Opponents argued that the projections rest on optimistic assumptions about population growth in corridors that have seen very little new housing built since the last comprehensive plan, and that the authority has historically overestimated demand on precisely the kind of suburban extension now proposed.Transit advocates who packed the chamber called the vote long overdue. Earlier proposals collapsed over disputes about which neighborhoods would host maintenance yards and how the costs would be shared between the city and the surrounding county, whose commission has yet to schedule its own vote on the funding agreement.The authoritys chief engineer told the council that early utility relocation work could begin as soon as the environmental review concludes, and that the agency has already begun the procurement process for the rolling stock it expects to need by the time the eastern line opens for revenue service.A spokesperson for the mayor said the administration considers the funding agreement settled and does not expect the county commission to reopen the cost-sharing formula, which was negotiated over eighteen months and signed by both executives before the council took up the measure this spring.Construction is expected to begin in March, pending final environmental review.对比 HTML 与期望输出可以发现三件事站点 Logodiv.logo被删除key-points与a-content a-content--logo-end两层包装被解除解包而非保留正文段落以纯 Markdown 段落形式输出标题、作者、站点名被正确提取到元数据中。选择器清理在 defuddle 处理管线中的位置在深入规则细节之前先明确这段逻辑所处的处理阶段。defuddle 的主流程位于 src/defuddle.ts其中removeBySelector是内容清理管线中的确定性清除步骤removeHiddenElements按计算样式剔除隐藏元素removeEyebrowLabel剔除标题上方的分类标签removeBySelector按 class/id/属性选择器确定性剔除已知非内容元素导航、页脚、侧栏、Logo 等在 src/defuddle.ts 中调用入口函数定义于 src/removals/selectors.tsremoveLowScoring基于链接密度等启发式打分剔除低分块运行在removeBySelector之后因此选择器阶段清理得越干净打分阶段看到的 DOM 越纯净。removeBySelector的调用还受两个开关控制removeExactSelectors与removePartialSelectors默认均为 true定义见 src/types.ts分别对应下面要讲的精确匹配与部分匹配两条路径。第一道防线精确选择器直接命中 Logo 容器defuddle 将特征非常明确的元素写死在EXACT_SELECTORS数组中src/constants.ts运行前用join(,)拼成一个巨型选择器字符串EXACT_SELECTORS_JOINED在 src/removals/selectors.ts 中通过一次querySelectorAll全部取出。与 Logo 相关的精确规则有三条src/constants.ts// logos [classlogo i], #logo, #Logo,注意第一条用的是完全相等的属性选择器[classlogo i]即只有当 class 属性值恰好是logo不区分大小写时才命中。本 fixture 中的div classlogo正是这种情况因此它在精确匹配阶段就被标记删除与后面的部分匹配逻辑无关。而a-content--logo-end的 class 值不是logo不会被这条规则命中。精确匹配阶段还有若干保护性跳过逻辑避免误伤正文跳过代码块内的元素el.closest(pre, code)防止语法高亮 span 被误删跳过带响应式显示类如 Tailwind 的hidden sm:flex的隐藏元素跳过mainContent的祖先元素防止正文容器本身被拔除。第二道防线部分选择器按词边界匹配 logo仅仅处理classlogo显然不够现实中大量站点使用site-logo、logo-wrapper、header-logo这类组合类名。这些靠PARTIAL_SELECTORS数组中的子串模式处理其中 logo 的规则是整条数组里最精密的一条src/constants.ts// Matches logo only at a class-token edge (site-logo, logo-wrapper). (?:(?![\\w-])logo|logo(?![\\w-])),这是一个词边界式正则含义是logo要么出现在 class token 的开头后面不能跟\w或-即后面是 token 结束要么出现在 token 的结尾前面不能是\w或-即前面是 token 开始。用这个规则验证本 fixture 中的两个候选class 值是否匹配原因logo已在精确阶段删除—精确选择器[classlogo i]命中site-logo匹配logo在 token 末尾前面是-lookaheadlogo(?![\\w-])成功logo-wrapper匹配logo在 token 开头lookbehind(?![\\w-])logo成功a-content--logo-end不匹配logo前后都是-两个方向的边界断言均失败关键就在a-content--logo-endlogo前面是-、后面也是-既不是 token 开头也不是 token 结尾于是两条分支(?![\\w-])logo与logo(?![\\w-])全部落空正文容器得以存活。这正是该 fixture 名称中 substring 一词的深意——规则并非简单的包含 logo 就删而是logo 作为一个独立词元出现才删从而在logo作为其他单词组成部分如catalog、dialogue以及本场景的 BEM 风格--logo-end修饰符时保持克制。如果改成朴素子串匹配logo那么a-content--logo-end会被命中并整体删除整篇正文随之丢失——本 fixture 就是用来永久防止这类回归的。部分匹配的完整判定流程removeBySelector的部分匹配阶段src/removals/selectors.ts并不只检查 class而是把多个测试属性拼接后统一做正则测试。测试属性定义在 src/constants.tsexport const TEST_ATTRIBUTES [ class, id, data-component, data-test, data-testid, data-test-id, data-qa, data-cy ];运行时会拼成[class],[id],[data-component],...这样的属性选择器TEST_ATTRIBUTES_SELECTORsrc/constants.ts一次性取出所有候选元素。对每个候选元素跳过已标记删除的元素、[data-defuddle]提取器输出内的元素以及 code/pre 及其内部元素——语法高亮、内联代码的类名如language-name、meta-很容易命中噪声词必须先排除非标题元素把class >赞分享后端【免费下载链接】defuddleGet the main content of any page as Markdown.项目地址https://gitcode.com/gh_mirrors/de/defuddle点击查看免费下载相关推荐Defuddle 社交互动计数器移除机制解析如何让 “13 Likes” 不污染提取的正文Defuddle 社交互动计数器移除机制解析如何让 “13 Likes” 不污染提取的正文 本文围绕 Defuddle 仓库中的 fixture 测试用例 c后端defuddle 内容模式清理实战代码块样板文本与文末冗余区块的自动剔除defuddle 内容模式清理实战代码块样板文本与文末冗余区块的自动剔除 本文以 defuddle 仓库中的测试样例 content patterns cod后端Sherlock 移除站点清单解析用户名探测的设计边界与站点剔除机制Sherlock 移除站点清单解析用户名探测的设计边界与站点剔除机制 Sherlock 是一个通过用户名并发探测各大网站个人主页的开源工具其站点数据以 JS网络安全CLI渗透测试上一篇5分钟永久备份QQ空间青春回忆GetQzonehistory使用指南下一篇GetQzonehistory3分钟永久保存你的QQ空间青春回忆创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

相关新闻

低代码零代码的发展趋势,恐象 AI 的 AI 融合方向

低代码零代码的发展趋势,恐象 AI 的 AI 融合方向

低代码与零代码行业,经历了多轮技术演进。早期产品以表单工具为主,功能单一;随后发展出可视化拖拽架构,可以搭建简单业务系统;如今大模型技术成熟,AI 能力开始融入低代码与零代码平台,催生了以自…

2026/10/15 3:17:37 阅读更多 →
達利烏傳——安陀羅毘迦國刪籍侯列傳

達利烏傳——安陀羅毘迦國刪籍侯列傳

達利烏傳——安陀羅毘迦國刪籍侯列傳 達利烏者,阿摩提氏,西海金山人也,生於癸亥。少好格物,遊諸名庠,先治物理,後究生物之理。學成,得博士,又留醫學之館,求辨疾之術。既見…

2026/10/15 3:17:37 阅读更多 →
KVM内存虚拟化实战:EPT、气球驱动、KSM、大页与NUMA调优指南

KVM内存虚拟化实战:EPT、气球驱动、KSM、大页与NUMA调优指南

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/15 3:16:37 阅读更多 →

最新新闻

2026大厂AI薪资大起底:普通研发卷到40万,Agent开发狂撒80万年薪?

2026大厂AI薪资大起底:普通研发卷到40万,Agent开发狂撒80万年薪?

2026年大厂AI薪资揭秘:普通研发岗薪资锚定40万左右,但竞争激烈;AI Agent开发岗(50-80K15薪)对标SSP,高薪且门槛低,企业抢“应用落地”人才;顶级AI科学家包揽80-220万年薪。求职建议分…

2026/10/15 4:00:45 阅读更多 →
婚恋系统的匹配为什么不能全交给算法:机筛、红娘终审与反馈回流

婚恋系统的匹配为什么不能全交给算法:机筛、红娘终审与反馈回流

十月初有篇报道被同行转了一圈:中国消费者报的观点是,面对个体差异极强的婚恋市场,单纯的算法匹配难以兼顾性格适配、相处模式这些软性维度,"AI 初筛 真人红娘终审"的双轨模式正在成为行业转型样本。做婚恋系统的工程师…

2026/10/15 4:00:45 阅读更多 →
从零入门计算机网络系列(五):UDP套接字编程实战——从核心API到客户端与服务器通信

从零入门计算机网络系列(五):UDP套接字编程实战——从核心API到客户端与服务器通信

本文从UDP Socket的基础出发,一路往下走。 先把socket、sockaddr_in这些最基础的概念讲清楚,再把字节序、recvfrom/sendto这对收发搭档逐一拆开。接着看服务端怎么bind,客户端为什么是隐式bind,INADDR_ANY又到底意味着什么。最后…

2026/10/15 4:00:45 阅读更多 →
不儿,豆包工作竟成了Codex、CC的第二个家?!

不儿,豆包工作竟成了Codex、CC的第二个家?!

大家好,我是常年在多个Agent之间反复横跳的袋鼠帝。我电脑里现在同时装着Codex、Claude Code、豆包工作等众多Agent,哪个顺手用哪个。哪个有羊毛薅哪个。但麻烦的是,每换一个Agent,我是谁、喜欢什么样的回答、上回任务做到哪了&am…

2026/10/15 4:00:45 阅读更多 →
Spring AOP 原理详解:从动态代理到切面注解的源码级剖析

Spring AOP 原理详解:从动态代理到切面注解的源码级剖析

~~ Talk is cheap. Show me the code. ~~本文基于 Spring Framework 5.x / Spring Boot 2.x 版本,讲解 Spring AOP 的核心机制与实现原理。一、引言AOP(Aspect-Oriented Programming,面向切面编程)是 Spring 框架的核心能力之一&a…

2026/10/15 4:00:45 阅读更多 →
Halcon 定位技术(Positioning)详解与算子说明

Halcon 定位技术(Positioning)详解与算子说明

Halcon 定位技术(Positioning)详解与算子说明 参考来源:Halcon 17.12 Operator Reference — Matching、2D Metrology、XLD Contours 章节 适用版本:Halcon 17.12(主基准)/ 20.11 / 22.11 / 24.05 官方示例路径:Applications/Matching/、Applications/Measuring-2D/、ex…

2026/10/15 3:59:45 阅读更多 →

日新闻

Docker Compose 容器化部署 ChirpStack LoRaWAN 网络服务器实战

Docker Compose 容器化部署 ChirpStack LoRaWAN 网络服务器实战

1. 为什么选择容器化方式部署 LoRa 网络服务LoRa 物联网项目落地时,网络服务器是整个链路的核心枢纽。它负责接收网关上报的数据包、完成去重与解密、再把有效载荷分发给上层应用。早期大家习惯把网络服务器直接装在物理机上,依赖一堆系统库和特定版本的…

2026/10/15 0:00:46 阅读更多 →
共享LLM服务下的跨模型自动扩缩容:Kubernetes实战与避坑指南

共享LLM服务下的跨模型自动扩缩容:Kubernetes实战与避坑指南

1. 共享推理服务里,扩缩容到底难在哪做过大模型推理服务部署的人,大概都经历过这样的场景:一个团队共用一套推理集群,A 业务跑的是 7B 的小模型,B 业务跑的是 72B 的大模型,C 业务白天流量高、晚上几乎归零…

2026/10/15 0:00:46 阅读更多 →
Systemd 启动阶段根文件系统只读之谜:fstab 与 remount-fs 服务深度解析

Systemd 启动阶段根文件系统只读之谜:fstab 与 remount-fs 服务深度解析

1. 引子:一次内核恐慌引发的追查先从一个真实场景说起。某次我给一台老旧的嵌入式设备折腾系统裁减,为了把启动时间压进两秒以内,我手贱地把一串自认为“没用”的 systemd 服务给 disable 了,其中就包括systemd-remount-fs.servic…

2026/10/15 0:00:46 阅读更多 →

周新闻

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

简介:基于 ARIMA、LSTM、Transformer 等模型的流感时间序列预测 Python 源码,面向计算机相关专业课程设计与期末大作业学生,以及项目实战学习者。内容覆盖预处理、平稳性检验、定阶、残差分析、多模型对比预测的完整时序建模流程,…

2026/10/14 3:30:28 阅读更多 →
影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别 做影刀RPA自动化,十个新手有八个栽在"往输入框里填东西"这件事上:要么填不进去,要么填了一半,要么直接把原来内容追加在后面。这背后的根因&…

2026/10/14 16:30:29 阅读更多 →
影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容 1. 认识影刀:什么场景该用RPA采小说数据 起点中文网的页面结构相对稳定——分类榜单、书籍详情、章节内容三块独立页面,跳转链路清晰。这种场景非常适合影刀自动化&#x…

2026/10/14 3:29:58 阅读更多 →

月新闻

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/15 0:14:36 阅读更多 →
Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/14 22:45:47 阅读更多 →
黑夜航拍船只数据集训练YOLOV5模型全流程解析

黑夜航拍船只数据集训练YOLOV5模型全流程解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/14 7:53:34 阅读更多 →