是否有一个谷歌的见解API? [英] Is there a Google Insights API?

查看:100
本文介绍了是否有一个谷歌的见解API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个API来自动检索谷歌的见解信息,另一种算法的一部分,但一直无法找到任何东西。在谷歌的第一个结果提供了蟒蛇插件,它已经过时的网站。

I've been looking for an API to automatically retrieve Google Insights information for part of another algorithm, but have been unable to find anything. The first result on Google delivers a site with a python plugin which is now out of date.

请问这样的API存在,或者有没有人写了一个插件,也许蟒蛇?

Does such an API exist, or has anyone written a plugin, perhaps for python?

推荐答案

据我所知,没有可作为尚未API,也不是有来自谷歌的见解中提取数据的方法的工作落实。不过,我已经找到了解决我的(略更具体)的问题,这可能真的只是通过了解一些术语多少次搜索来解决。

As far as I can tell, there is no API available as of yet, and neither is there a working implementation of a method for extracting data from Google Insights. However, I have found a solution to my (slightly more specific) problem, which could really just be solved by knowing how many times certain terms are searched for.

这可以通过与谷歌的接口来实现对建议web浏览器搜索栏的协议。当你给它一个字,它返回建议短语列表,以及每个阶段已经搜索次数(我不知道的时间单位,presumably在过去的一年)。

This can be done by interfacing with the Google Suggest protocol for webbrowser search bars. When you give it a word, it returns a list of suggested phrases as well as the number of times each phase has been searched (I'm not sure about the time unit, presumably in the last year).

下面是一些Python code这样做,略高于code适合于通过odewahn1在<一个href=\"http://answers.oreilly.com/topic/1526-how-to-use-the-google-suggest-api-to-come-up-with-topics-for-answers/\">O'reilly答案以及关于Python 2.6和更低的工作:

Here is some python code for doing this, slightly adapted from code by odewahn1 at O'reilly Answers and working on Python 2.6 and lower:

from sgmllib import SGMLParser
import urllib2
import urllib

# Define the class that will parse the suggestion XML
class PullSuggestions(SGMLParser):

   def reset(self):
      SGMLParser.reset(self)
      self.suggestions = []
      self.queries = []

   def start_suggestion(self, attrs):
      for a in attrs:
         if a[0] == 'data': self.suggestions.append(a[1])

   def start_num_queries(self, attrs):
      for a in attrs:
         if a[0] == 'int': self.queries.append(a[1])

# ENTER THE BASE QUERY HERE

base_query = ""  #This is the base query

base_query += "%s"
alphabet = "abcdefghijklmnopqrstuvwxyz"
for letter in alphabet:
   q = base_query % letter;
   query = urllib.urlencode({'q' : q})
   url = "http://google.com/complete/search?output=toolbar&%s" % query

   res = urllib2.urlopen(url)
   parser = PullSuggestions()
   parser.feed(res.read())
   parser.close()

   for i in range(0,len(parser.suggestions)):
      print "%s\t%s" % (parser.suggestions[i], parser.queries[i])

这至少可以解决部分问题,但​​遗憾的是它仍然难以可靠地获得搜索次数为任何特定的词或短语,不可能获得不同阶段的搜索历史。

This at least solves the problem in part, but unfortunately it is still difficult to reliably obtain the number of searches for any specific word or phrase and impossible to obtain the search history of different phrases.

这篇关于是否有一个谷歌的见解API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆