对于检索特定搜索/关键字的前10个Google搜索结果的最佳方法,我有点困惑。我只需要标题和网址(说明不是必需的)。
我正在使用Ruby,显然有很好的方法可以使用googleajax gem。我已经能够让它工作,但我担心它是一个已弃用的API,可能会在任何一天被逐步淘汰。此外,一次获得4个以上结果的解决方法并不是很干净。
我认为谷歌自定义搜索可能是一个选项,但100个查询的每日限制是有限的。我宁愿不抓谷歌,因为这违反了他们的条款。
我还有哪些其他选择才能使这项工作成功?任何json / ruby / rails选项对我都有用。谢谢!
答案 0 :(得分:0)
我建议使用'rest-client'gem。
RestClient.get 'google_api_url'
答案 1 :(得分:0)
首先发生在我身上,只是例子:
require 'open-uri'
require 'nokogiri'
require 'restclient'
words = ["Foo", "Bar", "Baz"]
staff = [].tap do |acc|
words.each do |word|
link = "https://www.google.com/search?q=#{word}"
page = Nokogiri::HTML(RestClient.get(link))
page.css('a')[27].text
.....................# <- and parse data what you need
end
end
答案 2 :(得分:0)
关于你愿意做出的权衡,你的问题并不是很明确,但你可能想要考虑更多:
I think the Google Custom Search might be an option but the daily limit of 100 queries is restricting. I would prefer to not scrape Google as it's a violation of their terms.
我使用谷歌自定义搜索,这很容易,但限制到位。如果您担心不违反Google的服务条款,这是唯一的方法。您需要决定是否愿意违反服务条款,如果不是,您应该只使用谷歌自定义搜索。
答案 3 :(得分:0)
如果您的要求在一天内超过100个查询,但不是每天/定期查询,并且如果Google结果不是必须的,您可以考虑使用Bing Search API。
Bing Search API每个月允许5000次查询,您可以选择在一天内查看所有查询。同样,如果您的要求不是每日/常规要求,并且您可以超越Google,那么这将解决您的问题。
否则,支付Google是您唯一的出路。
答案 4 :(得分:0)
我们遇到了同样的问题,我们用自己的后端构建了自己的gem。使用起来非常简单:
query = GoogleSearchResults.new q: "coffee"
hash_results = query.get_hash