【问题标题】:How to use unofficial Google Trend API ( pyGTrends.py)如何使用非官方的 Google Trend API (pyGTrends.py)
【发布时间】:2013-01-18 00:37:04
【问题描述】:

我开始学习 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'

【问题讨论】:

  • 错误的行号超出了pyGtrends.py file 中的行数。你修改了吗?
  • 没有。这是 github 上的原始代码。
  • 然后可能需要查看 pyGTrends.py 代码的副本。另外,能否复制粘贴真实的源代码和回溯?我注意到提供的文本中有拼写错误(例如“passwaord”和“pacakage”),这表明您可能是手动输入的。
  • 嗨,你有没有找到任何有效的解决方案。

标签: python google-trends


【解决方案1】:

你需要这样称呼它

from pytrends.pyGTrends import pyGTrends

【讨论】:

    【解决方案2】:

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

    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)
    

    【讨论】:

    • 嗨 Mona,我使用的是 Python3.x,我使用了与您编写的代码相同的代码,但出现了错误。 urllib.error.HTTPError:HTTP 错误 400:错误的请求文件“C:\Users\shivamkotwalia\Desktop\Testapp-shivam\Data Scraping\GoogleTrends.py”,第 23 行,在 connector = pyGTrends(google_username, google_password) init self._connect() 中的文件“C:\Anaconda3\lib\site-packages\pytrends\pyGTrends.py”,第 51 行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多