You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Floki移除HTML节点报错,如何修复CaseClauseError问题?

解决Floki find_and_update触发CaseClauseError的问题

问题根源

Floki.find_and_update/3的更新回调函数必须返回有效的Floki节点结构——比如标签三元组{tag, attrs, children}、普通文本字符串,或是节点列表。你返回的空字符串""不符合内部的模式匹配规则,因此触发了CaseClauseError。

正确解决方式

如果要直接移除目标节点,更新函数返回**空列表[]**即可:

Floki.find_and_update(html_doc, "div.xyz", fn _ -> [] end)

如果只是想清空节点内部内容(保留div.xyz标签本身),可以返回一个空内容的节点结构:

Floki.find_and_update(html_doc, "div.xyz", fn {tag, attrs, _} -> {tag, attrs, []} end)

内容的提问来源于stack exchange,提问作者wintermeyer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 13:10:46