Giter VIP home page Giter VIP logo

google-search's Introduction

Google deprecated their API, this package no longer works

Google Search

Fast, feature rich Google Search client. Search web results, images, books, local, patents, blogs and news using an elegant Ruby API with only a single dependency.

Dependencies

  • json gem

Features

  • Fast

  • Lazy Enumeration (requests more results from google, not all at once)

  • Populates Google::Search::Item’s blog, book, image, local, news, patent, video, and web

  • Clean, well documented source code

  • Full test coverage

Classes

- Google::Search                  | superclass of all other search classes. Is Enumerable
- Google::Search::Web             | web search.
- Google::Search::Blog            | blog search.
- Google::Search::Book            | book search.
- Google::Search::Image           | image search.
- Google::Search::Local           | local search.
- Google::Search::News            | news search.
- Google::Search::Patent          | patent search.
- Google::Search::Video           | video search.
- Google::Search::Response        | single request response, containing items. Is Enumerable
- Google::Search::Item            | single item, superclass of all other items.
- Google::Search::Item::Web       | single item containing web specific data.
- Google::Search::Item::Blog      | single item containing blog specific data.
- Google::Search::Item::Book      | single item containing book specific data.
- Google::Search::Item::Image     | single item containing image specific data.
- Google::Search::Item::Local     | single item containing local specific data.
- Google::Search::Item::News      | single item containing news specific data.
- Google::Search::Item::Patent    | single item containing patent specific data.
- Google::Search::Item::Video     | single item containing video specific data.

Arbitrary Query String Support

Arbitrary key / value pairs may be passed to Google::Search.new, all options passed that are not assigned (deleted) will pass on to be part of the query string.

For argument reference visit: code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_web

Items

Each item type (web, image, etc) is a subclass of Google::Search::Item, whose constant is Google::Search::Item::{Web, Image, Blog, etc}. Every aspect of google-search is well documented, so poke around to learn more or view spec/item_spec.rb for item attributes.

Image example

Below we simply create a new :image search, and pass a :query string. Query strings are urlencoded when Search#get_uri is called, so there is no reason to do so manually.

File.open('path/to/images.html', 'w+') do |file|
  Google::Search::Image.new(:query => 'Cookies').each do |image|
    file.write %(<img src="#{image.uri}">)
  end
end

More Information

  • View the source :)

License:

(The MIT License)

Copyright © 2009 TJ Holowaychuk <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, an d/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

google-search's People

Contributors

0zguner avatar hirocaster avatar jikkujose avatar samsheff avatar tj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-search's Issues

Warning: instance variable @each_response not initialized

I'm working on a feature for the faker gem that would utilize this gem, and anytime I run the tests for it, it prints this message a lot.

I was able to solve it by declaring @each_response as nil in the initialize, but would love feedback from others as well

Some searches do not work

It seems some searches do not get results. When searching for 8715664020388 i get no results through google-search gem. When I google it myself, I do get search results. I encounter the problem with a lot of queries.

How do you prefer to have proxy support?

Hi TJ,

I've checked out your gem because I need to create a toy metasearch engine, the thing is that I need to have proxy support to pass through my university network, and I was about to create a patch.

As you already know, adding proxy support is trivial but, in order to keep the excellent usability of the API I was wondering which one of the following approaches would you prefer me to follow:

  • On the one side, I can keep the stateless, self-containing style of the queries and do what's necessary to allow something like this:
Google::Search::Web.new(:query => 'naked celebrities',  :proxy => 'http://proxy.uniovi.es:8888').each do |web_result|
   #... Whatever
 end
  • On the other side, it could be interesting to have a means of configuring a proxy for all the queries, as it is very likely that someone needing a proxy to submit a query, would need it to submit all of them:
Google::Search::Defaults.set(:proxy, 'http://proxy.uniovi.es:8888')
Google::Search::Web.new(:query => 'naked celebrities').each{ | web_result | ... }
Google::Search::Images.new(:query => 'angelina jolie').each{ | image | ... }
Google::Search::Local.new(:query => 'foo bar').each{ |place| ... }

Both alternatives can be complementary.

Do you think that having a Defaults object would break your API orthogonality? having it would ease the case of needing a proxy, which IMHO is not that uncommon, but I would like to know your opinion.

Regards,

Miguel

cannot load such file -- google-search

I am trying to require google-search gem inside a helper module, but getting the following error on require cannot load such file -- google-search. This is working well at the local system, but causing problems at the production server. Though I can find the gem when I run gem list. Unable to figure out the problem.

module TestHelper
   require 'google-search'

end

Possible New Bug With "site:foo.*"

I'm trying to simulate a search like this:

https://www.google.com/search?q=site:xapo.*
Results: xapo.com xapo.ch xapo.de xapo.info xapo.at xpo.co.pt etc...

What I have is something like this:

q = Google::Search::Web.new query: "site:xapo.*"

q.get_uri
# http://www.google.com/uds/GwebSearch?start=0&rsz=large&hl=en&key=notsupplied&v=1.0&q=site%3Axapo.%2A&filter=1

q.take 100
# Results: xapo.com foo.xapo.com etc...

The results are way different. What am I doing wrong?

Google::Search::News is not displaying any news articles. Please help.

Before it was Image, now even news articles are NOT being displayed from Google::Search::News. Please somebody help here. I m doing my final year project and desperately need some help. I tried it on irb. The result was NIL.

2.3.0 :008 > Google::Search::News.new(query: "Panama Papers")
`2.3.0 :009 > results = _
=> #<Google::Search::News:0x00000000e597c8 @relative_to=nil, @edition=nil, @order_by=nil, @type=:news, @Version=1.0, @offset=0, @SiZe=:large, @language=:en, @query="Panama Papers", @api_key=:notsupplied, @options={}>

2.3.0 :010 > results.each do |result|
2.3.0 :011 >     puts result
2.3.0 :012?>   end

=> nil `

Ruby gem Error “Google is not a module/class”

When I first require 'roo' and then require 'google-search' I get an error

TypeError: Google is not a module

Again, I first require 'google-search' and then require 'roo' I get this error

TypeError: Google is not a class

See below for what actually happened on irb

{12:30}[1.9.3]~ ➭ irb
1.9.3-p0 :001 > require 'roo'
=> true
1.9.3-p0 :002 > require 'google-search'
TypeError: Google is not a module
from /home/sagar/.rvm/gems/ruby-1.9.3-p0/gems/google-search-1.0.3/lib/google-search/version.rb:2:in <top (required)>' from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:inrequire'
from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in require' from /home/sagar/.rvm/gems/ruby-1.9.3-p0/gems/google-search-1.0.3/lib/google-search.rb:26:in<top (required)>'
from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in require' from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:inrescue in require'
from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in require' from (irb):2 from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in

'
1.9.3-p0 :003 > exit
{12:30}[1.9.3]~ ➭ irb
1.9.3-p0 :001 > require 'google-search'
=> true
1.9.3-p0 :002 > require 'roo'
TypeError: Google is not a class
from /home/sagar/.rvm/gems/ruby-1.9.3-p0/gems/roo-1.10.1/lib/roo/google.rb:7:in <top (required)>' from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:inrequire'
from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in require' from /home/sagar/.rvm/gems/ruby-1.9.3-p0/gems/roo-1.10.1/lib/roo.rb:74:in<top (required)>'
from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in require' from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:inrescue in require'
from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in require' from (irb):2 from /home/sagar/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in'

Google::Search::Image Returning 0 results

Over the last two days Google::Search::Image.new(:query => "anything") has been returning 0 results. I haven't touched any part of my google search code, and the results used to return perfectly. Google::Search::Web also still works. Is this specific to my app or has something happened with Google? Thanks for your help, great gem!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.