Skip to content

Instantly share code, notes, and snippets.

@bastos
Created October 17, 2008 12:37
Show Gist options
  • Save bastos/17403 to your computer and use it in GitHub Desktop.
Save bastos/17403 to your computer and use it in GitHub Desktop.
Busca de anúncios no diário do nordeste
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'cgi'
cgi = CGI.new() # New CGI object
puts "Content-type: text/html\n\n"
puts "<h1>Procurando por #{cgi.params['q']}</h1>"
doc = Hpricot(open("http://diariodonordeste.globo.com/classif/consultando.asp?Filtro=#{cgi.params['q']}&Operador=OU&Filtro2="))
doc.search(".anuncio").each do | anuncio |
puts '<div style="margin-top:10px;border-top:1px solid #333;padding:5px;">'
puts '<p>'
puts anuncio.inner_text.strip
puts '</p><p>Telefone:<br />'
puts anuncio.inner_text.scan(/[0-9]{4}+\.[0-9]{4}+/).join(', ')
puts '</p></div>'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment