Google Scrap con Rails
Posted: June 13th, 2009 | Author: FreedomCoder | Filed under: Open Source, Programming, Rails | Tags: Google, Open Source, Programming, Rails, search | No Comments »
web_search_plugin es un nuevo plugin de Rails que hice, para poder obtener los resultados de una determinada consulta en google y mostrarla en tu sitio. Hasta el momento solo realiza búsquedas en Google, a futuro lo voy a integrar con Yahoo y Live.
Instalar web_search_plugin
# cd myapprails # ruby script/plugin install git@github.com:chebyte/web_search_plugin.git
Uso
Como ejemplo, tenemos el modelo #link.rb
class Link < ActiveRecord::Base include Chebyte::WebSearch web_search end
Ahora para obtener los resultados solo debemos llamar al método search_web
Link.google_search(:query => "tuquito")
esto nos devolveria
=> #<Google::Response:0xb734d3cc @results=[{:domain=>"www.tuquito.org.ar", :content=>"Proyecto Linux de Tucumán, datos y temas relacionados al proyecto, foros y ayuda para usuarios de la distribución y descargas.", :title=>"Tuquito 3", :cache_url=>"http://www.google.com/search?q=cache:4NZXKc3gQA8J:www.tuquito.org.ar", :url=>"http://www.tuquito.org.ar/"}, {:domain=>"en.wikipedia.org", :content=>"Oct 11, 2008 ... Tuquito is a Debian-based operating system created in Tucumán, Argentina, by Ignacio Díaz, Chris Arenas and Mauro Torres, students of The ...", :title=>"Tuquito - Wikipedia, the free encyclopedia", :cache_url=>"http://www.google.com/search?q=cache:a1xAEvHHujUJ:en.wikipedia.org", :url=>"http://en.wikipedia.org/wiki/Tuquito"}, {:domain=>"www.slideshare.net", :content=>"Tuquito 3 Nuevo Diseño En varios idiomas (Ingles,Portugues y Español) Interfaces mas intuitivas Optimizado para la conectividad(wifi, ...", :title=>"Tuquito 3", :cache_url=>"http://www.google.com/search?q=cache:T8VfO-4iyioJ:www.slideshare.net", :url=>"http://www.slideshare.net/chebyte/tuquito-3"}, {:domain=>"www.olpcnews.com", :content=>"OLPC Tuquito's team began to work at 1st January of 2007, with the knowledge acquisition about the project One Laptop Per Child and then with development ...", :title=>"OLPC Tuquito Project Progress in Argentina - OLPC News", :cache_url=>"http://www.google.com/search?q=cache:eoGfDNbaZ8kJ:www.olpcnews.com", :url=>"http://www.olpcnews.com/countries/argentina/olpc_tuquito_project_argentina.html"}], @status=200, @size=4, @query="tuquito">
El resultado es un simple objecto hash, algunos de los campos disponibles son
* title titulo del resultado
* url Url del resultado
* domain Root url del resultado
* content contenido
* cache_url Google cache url
(Via Chebyte’s Blog.) Original Link: Google Scrap con Rails
Leave a Reply