Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Zeke Sikelianos

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Mechanize / Hpricot / Scraping setup

   1  
   2  require 'rubygems'
   3  require 'cgi'
   4  require 'open-uri'
   5  require 'hpricot'
   6  require 'mechanize'
   7  
   8  agent = WWW::Mechanize.new
   9  doc = Hpricot(agent.get(the_url).parser.to_s)

Scraping Google Search Results with Hpricot

// snagged from http://g-module.rubyforge.org/

   1  
   2  require 'rubygems'
   3  require 'cgi'
   4  require 'open-uri'
   5  require 'hpricot'
   6  
   7  q = %w{meine kleine suchanfrage}.map { |w| CGI.escape(w) }.join("+")
   8  url = "http://www.google.com/search?q=#{q}"
   9  doc = Hpricot(open(url).read)
  10  lucky_url = (doc/"div[@class='g'] a").first["href"]
  11  system 'open #{lucky_url}'
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS