在 nokogiri 中解析多个没有 root 的标签

发布于 2024-12-25 03:06:34 字数 239 浏览 1 评论 0原文

我想做这样的事情:

fragment = parse("<p></p> <p></p>")
another_node.add_child(fragment)

但到目前为止,我还没有找到任何可以完成这项工作的东西 - 所有东西都需要一个具有多个子节点的根节点。关于如何实现这一目标有什么想法吗?这个要求似乎并没有那么奇怪,我觉得我一定错过了一些东西。

I'm looking to do something like this:

fragment = parse("<p></p> <p></p>")
another_node.add_child(fragment)

But so far I haven't found anything that does the job - everything wants one root node with multiple children. Any ideas about how to accomplish this? It doesn't seem like it's that odd a request, and I feel like I must be missing something.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后eg是否自 2025-01-01 03:06:34

这有效:

fragment = Nokogiri::HTML.fragment("<p></p> <p></p>")
another_node = Nokogiri::HTML.fragment("<div></div>")
another_node.add_child(fragment)

This works:

fragment = Nokogiri::HTML.fragment("<p></p> <p></p>")
another_node = Nokogiri::HTML.fragment("<div></div>")
another_node.add_child(fragment)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文