views:

82

answers:

1

How to fetch the contents of meta name="description" content="....." with Scrubyt ?

require 'rubygems'
require 'scrubyt'


data = Scrubyt::Extractor.define do
  fetch 'http://www.allegro.pl/'

  head '//head' do
    description '//meta[@name="description"]'
  end
end

puts data.to_xml

What is the the correct way ?

+2  A: 

If you want the value of the content attribute try:

head '//head' do
  description '//meta[@name="description"]/@content'
end

//meta[@name="description"] selects the meta tag whose name attribute is equal to "description" but then you also need to select the value of the content attribute.

mikej
Exactly, from where do You know the trick ?
astropanic
It is a standard syntax for selecting attribute values that Scrubyt is using. What you are doing is also similar to the example at http://github.com/scrubber/scrubyt_examples/blob/master/favicon.rb which gets the favicon URL from a page.
mikej