如何使用Nokogiri获取Meta关键字?

时间:2012-03-04 10:15:54

标签: ruby nokogiri

我正在使用Nokogiri进行任务,我正在努力解决这个问题。这伤害了我的大脑。任何导致解决方案的步骤,提示或示例都很可爱。

1 个答案:

答案 0 :(得分:18)

这是一个简单的例子:

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