public
Description: A handful (but hopefully growing amount) of scRUBYt! examples
Homepage: http://scrubyt.org
Clone URL: git://github.com/scrubber/scrubyt_examples.git
scrubyt_examples / yahoo.rb
100644 26 lines (19 sloc) 0.602 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Yahoo suggestions scraping
#
# Not trivial as the suggestions are dynamically loaded into a popup
require 'rubygems'
require 'scrubyt'
require 'cgi'
 
Scrubyt.logger = Scrubyt::Logger.new
 
 
yahoo_data = Scrubyt::Extractor.define :agent => :firefox do
  fetch 'http://www.yahoo.com'
  fill_textfield_and_wait 'p', 'ruby', 5
  
  suggestion_list "//div[@id='ac_container']//li/a", :example_type => :xpath do
    href "href", :type => :attribute do
      escaped_string /&p=(.+?)$/ do
        suggestion lambda {|x| CGI::unescape(x)}, :type => :script
      end
    end
  end
end
 
p yahoo_data.to_hash