Question

I was wondering if anyone knows of any good code/applications/Gems to grab meta data (title & description) from any website?

I have a recipe site and users can add the URL of where they got the recipe from, I want to auto generate a title and description of the site from this URL submitted.

Any ideas/ thanks for your help!

Était-ce utile?

La solution

Nokogiri is a simple html parser, since you just want the meta tag information that should be simple enough.

require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://www.example.com'))
doc.xpath('//meta').each do |meta|
  puts meta.name
  puts meta.content
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top