Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Meta Keywords using Nokogiri?

Tags:

ruby

nokogiri

I'm using Nokogiri for an assignment and I'm struggling to figure this out. It's hurting my brain. Any steps, hints, or examples leading to the solution would be lovely.

like image 733
Josh Brody Avatar asked Mar 04 '12 10:03

Josh Brody


1 Answers

Here is a simple example:

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
like image 52
Sébastien Le Callonnec Avatar answered Oct 21 '22 12:10

Sébastien Le Callonnec