0

我有以下代码,我使用了来自 dominolab 的代码示例:

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

google_username = "myusername"
google_password = "mypassword"
path = "csv_files"

if not os.path.exists(path):
    os.makedirs(path)

base_keyword = "/m/0k44x" #Image Processing

terms = [
    "Image Processing",
    "Signal Processing",
    "Computer Vision",
    "Machine Learning",
    "Information Retrieval",
    "Data Mining"
]

advanced_terms = [
    "/m/07844",
    "/m/0yk6",
    "/m/05kx1v",
    "/m/04zv0zl",
    "/m/017chx",
    "/m/0cqyr9",
    "/m/0121sb",
    "/m/07844",
    "/m/06dq9"
]
# connect to Google Trends API
connector = pyGTrends(google_username, google_password)


for label, keyword in zip(terms, advanced_terms):
    print(label)
    sys.stdout.flush()
    keyword_string = '"{0}, {1}"'.format(keyword, base_keyword)
    connector.request_report(keyword_string, geo="US", date="01/2014 65m")
    # 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)

但是,我在保存的 CSV 文件中看到了这些:

<div id="report">
    <div class="errorTitle">An error has been detected</div>
    <div class="errorSubTitle">This page is currently unavailable. Please try again later.<br/> Please make sure your query is valid and try again.<br/> If you're experiencing long delays, consider reducing your comparison items.<br/> Thanks for your patience.</div>
  </div>

出了什么问题,如何解决?我从 Google Trend 获取数据,这里有一个例子

4

1 回答 1

2

我认为问题出在日期查询上date = "01/2014 65m",您要在 2014 年 1 月之后的 65 个月内询问它……但那是在未来!

因此,这是日期的正确格式:

connector.request_report(keyword_string, geo="US", date="01/2014 5m")
于 2016-07-29T03:55:43.557 回答