Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Scraping Google Search Results With Hpricot

DZone's Guide to

Scraping Google Search Results With Hpricot

·
Free Resource
// snagged from http://g-module.rubyforge.org/


require 'rubygems'
require 'cgi'
require 'open-uri'
require 'hpricot'

q = %w{meine kleine suchanfrage}.map { |w| CGI.escape(w) }.join("+")
url = "http://www.google.com/search?q=#{q}"
doc = Hpricot(open(url).read)
lucky_url = (doc/"div[@class='g'] a").first["href"]
system 'open #{lucky_url}'
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}