How can I parse out the doctype tag to get the html version from a html file?
Trying to use doctype(or DOCTYPE or !DOCTYPE) 开发者_开发技巧as an argument in xpath raises an invalide expression error.
The doctype is not part of the document, but part of its 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
精彩评论