Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to get google search results?

I want to get all the search results for a particular keyword search on google. I've seen suggestions of scraping, but this seems like a bad idea. I've seen Gems (I plan on using ruby) that do scraping and use the API. I've also seen suggestions of using the API.

Does anyone know the best way to do this right now? The API Is no longer supported and I've seen people report they get unusable data back. Do the Gems help solve this or no?

Thanks in advance.

like image 497
Noah Clark Avatar asked Nov 17 '11 18:11

Noah Clark


People also ask

Why is Google not showing proper search results?

Restart your device and try your search again. If you're able to connect to the Internet, update the Google app to the latest version. To check if you get results, try your search again. When you clear an app's cache, you delete data stored in a temporary area of the device's memory.


2 Answers

I also go for the scrape option, its quicker than asking google for a key and plus, and you are not limited to 100 search queries per day. Google´s TOS is an issue though, as Richard points out. Here´s an example i´ve done that works for me - it´s also useful if you want to connect through a proxy:

require 'rubygems'
require 'mechanize'

agent = Mechanize.new
agent.set_proxy '78.186.178.153', 8080
page = agent.get('http://www.google.com/')

google_form = page.form('f')
google_form.q = 'new york city council'

page = agent.submit(google_form, google_form.buttons.first)

page.links.each do |link|
    if link.href.to_s =~/url.q/
        str=link.href.to_s
        strList=str.split(%r{=|&}) 
        url=strList[1] 
        puts url
    end 
end
like image 146
fartagaintuxedo Avatar answered Sep 21 '22 03:09

fartagaintuxedo


According to http://code.google.com/apis/websearch/ , the Search API has been deprecated -- but there's a replacement, the Custom Search API. Will that do what you want?

If so, a quick Web search turned up https://github.com/alexreisner/google_custom_search , among other gems.

like image 30
Marnen Laibow-Koser Avatar answered Sep 24 '22 03:09

Marnen Laibow-Koser