Google趋势"检测到错误"

时间:2016-07-29 03:36:39

标签: python csv ipython jupyter google-trends

我有以下代码,我使用了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趋势和an example获取了数据。

1 个答案:

答案 0 :(得分:2)

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

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

connector.request_report(keyword_string, geo="US", date="01/2014 5m")