PyTrends不断返回Google响应,错误代码为400

时间:2018-11-24 21:37:40

标签: python-3.x pandas google-trends

我一直在尝试为许多不同的关键字提取google趋势数据,并一直在使用熊猫遍历每个关键字来构建每个有效载荷。但是,当我尝试使用关键字的特定行时,我一直收到Google错误代码400。这是我目前拥有的代码

import csv
import time
import pandas as pd
from random import randint
from pytrends.request import TrendReq

# set gmail credentials and path to extract data


# Login to Google. Only need to run this once, the rest of requests will use the same session.
pytrend = TrendReq()
keywordcsv = "nba.csv"
keywords = pd.read_csv(keywordcsv)
print(keywords)
for index, row in keywords.iterrows():
    print("Downloading Keyword #" + str(index))
    temp = str(row[0])
    pytrend.build_payload(kw_list=temp, timeframe="2013-11-24 2018-11-11", geo='US')
    time.sleep(randint(5, 10))
    null_df = pytrend.interest_over_time()
    print(null_df)
    null_df.to_csv(path_or_buf='blah.csv', mode='a', header=0)

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我遇到了这个错误。结果表明您要比较的关键字的最大长度为 5。