gpt4 book ai didi

ruby - 在 Nokogiri 中解析出 html doctype 标签

转载 作者:数据小太阳 更新时间:2023-10-29 07:31:04 24 4
gpt4 key购买 nike

如何解析 doctype 标签以从 html 文件中获取 html 版本?

尝试使用 doctype(或 DOCTYPE 或 !DOCTYPE)作为 xpath 中的参数会引发无效表达式错误。

最佳答案

doctype 不是文档的一部分,而是 DTD 的一部分

require 'rubygems'
require 'nokogiri'

html = <<EOF
<!DOCTYPE foo PUBLIC "bar" "qux">
<html>
</html>
EOF

doc = Nokogiri::HTML(html)

puts doc.internal_subset.name
puts doc.internal_subset.external_id
puts doc.internal_subset.system_id

关于ruby - 在 Nokogiri 中解析出 html doctype 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5657360/

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