3

我开始学习python来制作一个用于抓取网络数据的程序。所以我在谷歌上搜索,发现了谷歌趋势 API,pyGTrend.py。但我不能使用它。我可以在谷歌找到同样的问题,但没有我能理解的解决方案。请帮我。

我刚刚使用了 API 所有者网站上所写的 API:Programmatic Google Trends Api

from pyGTrends import pyGTrends

connector = pyGTrends('googleID','passwaord')
connector.download_report(('banana', 'bread', 'bakery'),date='2008-4',geo='AT',scale=1)
print connector.csv()

错误信息如下,

Traceback(most recent call last):
File ('Stdin') line1, in <Module>
File "C:\Pyhon27\Lib\site-pacakage\pyGTrends.py" line 115, in csv
KeyError: 'main'
4

2 回答 2

2

你需要这样称呼它

from pytrends.pyGTrends import pyGTrends
于 2016-03-06T21:41:51.383 回答
0

这是一个如何使用它的示例。如果您需要进一步的帮助,请告诉我:

from pytrends.pyGTrends import pyGTrends
import time
from random import randint
from IPython.display import display
from pprint import pprint
import urllib
import sys

google_username = "GMAIL_USERNAME"
google_password = "PASSWORD"
path = "."

terms = [
    "Image Processing",
    "Signal Processing",
    "Computer Vision",
    "Machine Learning",
    "Information Retrieval",
    "Data Mining"
]
# connect to Google Trends API
connector = pyGTrends(google_username, google_password)


for label in terms:
    print(label)
    sys.stdout.flush()
    #kw_string = '"{0}"'.format(keyword, base_keyword)
    connector.request_report(label, geo="US", date="01/2014 96m")
    # wait a random amount of time between requests to avoid bot detection
    time.sleep(randint(5, 10))
    # download file
    connector.save_csv(path, label)

for term in terms:
    data = connector.get_suggestions(term)
    pprint(data)
于 2016-07-29T02:38:32.940 回答