class MetaInspector VERSION = '1.0.1' Hpricot.buffer_size = 300000 def self.scrape(url) doc = Hpricot(open(url)) # Searching title... if (!doc.at('title').nil?) title = doc.at('title').inner_html else title = "" end # Searching meta description... if (!doc.at("meta[@name='description']").nil?) description = doc.at("meta[@name='description']")['content'] else description = "" end # Searching meta keywords... if (!doc.at("meta[@name='keywords']").nil?) keywords = doc.at("meta[@name='keywords']")['content'] else keywords = "" end # Searching links... links = [] doc.search("//a").each do |link| links << link.attributes["href"] if (!link.attributes["href"].nil?) end # Returning all data... {'ok' => true, 'title' => title, 'description' => description, 'keywords' => keywords, 'links' => links} end end