page scraping in Ruby

Using Mechanize + Nokogiri

What to do if failed

Anyway, simple scraping code


require 'rubygems'
require 'mechanize'

a = Mechanize.new { |agent|
    agent.user_agent_alias = 'Mac Safari'
    agent.set_proxy 'proxy.houston.hp.com', 8080
}

page = a.get('http://google.com/search?q=Hello+World')

page.links.each do |link|
    puts link.uri
end

No comments: