同时运行多个google趋势查询error messag

2024-04-26 06:20:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在同一时间运行多个谷歌趋势查询,以便能够比较趋势得分。我知道这个问题在stackoverflow上被问了好几次,但是这个问题更具体。我不断收到以下错误消息:

ResponseError: The request failed: Google returned a response with code 400.

我创建了一个包含多个字符串的列表,称为“查询”,这里的输出:

['Green Day Boulevard of Broken Dreams',
'Linkin Park In The End',
'The White Stripes Seven Nation Army',
'Red Hot Chili Peppers By The Way',
'Nickelback How You Remind Me',
'Evanescence Bring Me To Life',
'Papa Roach Last Resort',
'Jet Are You Gonna Be My Girl',
'The Killers Mr. Brightside',
'Kings of Leon Sex on Fire']

from pytrends.request import TrendReq
trend = TrendReq()
trend.build_payload(kw_list=queries, timeframe="all")

上面的错误消息就是输出。有趣的是,如果我创建了一个新的列表(手写的,“查询”列表是通过循环数据帧创建的),比如

qu = ['germany', 'usa']

代码完美地工作并输出我想要的:

interest_over_time_df = trend.interest_over_time()
interest_over_time_df.drop("isPartial",axis=1).max()

我的结论是:“查询”列表中的某些内容是错误的,但在我看来它们是相同的。你知道吗


Tags: oftheyou消息df列表timerequest