gpt4 book ai didi

html - 在 Ruby 中转换回 HTML

转载 作者:太空宇宙 更新时间:2023-11-03 16:16:58 24 4
gpt4 key购买 nike

我正在解析 HTML 内容:

doc = Nokogiri::HTML::DocumentFragment.parse(html_content)

我正在用类名“pubdate online”替换 p 标签中的文本。

doc.css("p.pubdate.online").each do |node|
node.content = self.send("#{article_type}_released_at").strftime("%B %d, %Y")
end

我正在尝试将解析后的 H​​TML 转换回原始 HTML。

 doc.to_html

但现在 doc.to_html没有 <DOCTYPE!><head>标签或 <body>标签。所以问题是在使用 HTML 时我得到的是原始 HTML 代码而不是 HTML 页面。帮助我将文档转换回带有替换文本的原始 HTML 内容。

最佳答案

如前所述here ,你能试试这个吗:

node = doc.at_css("p.pubdate.online")
node.content = self.send("#{article_type}_released_at").strftime("%B %d, %Y")
doc.to_html

关于html - 在 Ruby 中转换回 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41690855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com