Do a google search and parse the result html : open uri « Network « Ruby






Do a google search and parse the result html


#!/usr/bin/env ruby

require 'open-uri'

url = "http://www.google.com/search?q=ruby"

open(url) { |page| page_content = page.read()

  links = page_content.scan(/<a class=l.*?href=\"(.*?)\"/).flatten

  links.each {|link| puts link}

}

 








Related examples in the same category

1.The open-uri Library
2.Opening a URI
3.Get a file from a URL
4.open in a block style:
5.use open directly upon URI objects
6.the shortest open-uri code possible
7.use methods associated with the object it returns to find out particulars about the HTTP (or FTP) response itself.
8.send extra header fields with an HTTP request by supplying an optional hash parameter to open
9.Use openuri to open a web link