2012-03-04 12 views

risposta

16

Ecco un semplice esempio:

require 'rubygems' 
require 'nokogiri' 


doc = Nokogiri::HTML("<html><head><meta name=\"Keywords\" content=\"one, two, three\"></head><body></body></html>") 

doc.xpath("//meta[@name='Keywords']/@content").each do |attr| 
    puts attr.value 
end 
+5

dato che c'è solo supposta per essere una, forse doc.at ('meta [@ name = "keywords"]') [: content] ha più senso – pguardiario

+0

No , sbagliato. deve essere case sensitive. metaKeywords = doc.xpath ('// meta [case_insensitive_equals (@name, "keywords")]', XpathFunctions.new) [0] .attributes ["content"]. value –

Problemi correlati