Google趋势配额限制

Gra*_*Gee 6 google-api limit quota

我试图从Google趋势中提取数据,并在仅仅尝试2次后得到"您已达到每日限额"错误.

有没有办法解决这个问题?我知道Google API项目有特殊的配额限制,但Google趋势没有API.我还读到我们可能需要将它传递给一个cookie文件,这样我才能登录.有没有人遇到过这个问题?

Pav*_*nov 5

我正在努力解决同样的问题!从你的问题我无法弄清楚你达到了哪个阶段......但这是我找到的解决方案:

  1. 您应该使用 cookie 模拟浏览器。我认为最好的方法是使用Mechanize库。
  2. 首先,您的程序应该使用 GET 请求“登录”到“ https://accounts.google.com/Login?hl=en
  3. 之后您可以立即访问其他一些个人资源,但不能访问谷歌趋势!
  4. 经过一段显著的时间就可以顺利拿到谷歌趋势的数据为CSV。
  5. 我还没有发现确切的时间段,但它是超过 10 分钟,不到几个小时:)。这就是为什么保存您的 cookie 以备后用的原因是个好主意!

还有一些提示:

  • 如果您在 Windows 下使用 python/ruby 进行开发,请不要忘记为 OpenSSL 库设置 CA ROOT 证书包。否则HTTPS连接将失败,您将无法登录!请参阅获取 Mechanize 对象的“证书验证失败 (OpenSSL::SSL::SSLError)”错误

  • 我建议您在程序关闭时将 cookie 保存到外部文件。并在启动时恢复它们。

  • 不要忘记允许重定向,因为 Google 一直在使用重定向。

Ruby 代码示例:

require 'mechanize'
require 'logger'
begin
  agent = Mechanize.new { |a|
    a.user_agent = 'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.16'

    cert_store = OpenSSL::X509::Store.new
    cert_store.add_file 'cacert.pem'
    a.cert_store = cert_store

    a.log = Logger.new('mech.log')

    if File.file?('mech.cookies')
      cookies = Mechanize::CookieJar.new
      cookies.load('mech.cookies')
      a.cookie_jar = cookies
    end

    a.open_timeout = 5
    a.read_timeout = 6
    a.keep_alive   = true
    a.redirect_ok  = true
  }

  LOGIN_URL = "https://accounts.google.com/Login?hl=en&continue=http://www.google.com/trends/"
  login_page = agent.get(LOGIN_URL)
  login_form = login_page.forms.first
  login_form.Email = *
  login_form.Passwd = *
  login_response_page = agent.submit(login_form)

  page = agent.get(url)

  # DO SOME TRENDS REQUESTS AFTER SIGNIFICANT PERIOD OF TIME

ensure
  if agent
    agent.cookie_jar.save('mech.cookies')
  end
end
Run Code Online (Sandbox Code Playgroud)


小智 4

您可能禁用了 cookie,这使得 Google 趋势认为您是机器人