2010-04-20 93 views
8

我正在嘗試使用Ruby進行Google搜索,並打印出前3個結果。在Ruby中使用Google搜索REST API

任何人都可以指向我的示例代碼?我無法找到它。

+0

我的答案有問題嗎? – 2010-05-05 15:51:23

+0

對不起,忘了選擇它。非常感謝! :) – Dogbert 2010-05-06 21:44:29

回答

7

寶石googleajax是有是:

require 'googleajax' 
GoogleAjax.referer = "your_domain_name_here.com" 
GoogleAjax::Search.web("Hello world")[:results][0...3] 
+1

僅供參考:截至2010年11月,Google Web Search API已棄用。它繼續運行,但結果對我來說看起來很奇怪,並且與Web UI所提供的截然不同。 – 2011-09-06 07:39:20

+1

然後用什麼? – Schovi 2012-01-03 13:56:02

+0

例如:'r = GoogleAjax :: Search.web(「Hello world」)[:results] [0]'then'puts r [:unescaped_url]' – craig 2014-08-10 21:35:07