首页 > 解决方案 > 谷歌趋势分类搜索

问题描述

我正在尝试根据以下链接中的此列表使用 Python按类别和/或子类别提取/下载 Google 趋势系列数据: https ://github.com/pat310/google-trends-api/wiki/Google-Trends -类别

此类别列表包含在 Google 趋势的(非官方)API 中使用的代码,名为pytrends。但是,我不能只按类别搜索,因为它需要提供关键字/搜索词。在下面的例子中,我们有类别 47(汽车和车辆)和关键字 ['BMW', 'Peugeot']。

import pytrends
from pytrends.request import TrendReq

pytrend = TrendReq()


pytrend = TrendReq(hl='en-US', tz=360)
keywords = ['BMW', 'Peugeot']
pytrend.build_payload(
     kw_list=keywords,
     cat=47,
     timeframe='today 3-m',
     geo='FR',
     gprop='')
data = pytrend.interest_over_time()
data= data.drop(labels=['isPartial'],axis='columns')
image = data.plot(title = 'BMW V.S. Peugeot in last 3 months on Google Trends ')
fig = image.get_figure()

我发现这是一个可能的解决方案,但我没有尝试过,因为它在 R 中: https ://github.com/PMassicotte/gtrendsR/issues/89

我不知道是否有 API 可以按类别提取系列并忽略关键字/搜索词。让我知道它是否存在。我相信一个选择是直接从谷歌趋势网站下载并填写类别字段,就像这个例子一样,我们可以看到类别“汽车和车辆”的系列: https ://trends.google.com/trends/探索?cat=47&date=all&geo=SG

标签: pythoncategoriesgoogle-trends

解决方案


您可以通过 kw_list 数组中的空字符串类别进行搜索:

keywords = ['']

pytrend.build_payload(kw_list=[''], cat=47,
                           timeframe='today 3-m', geo='FR', gprop='')
data = pytrend.interest_over_time()

推荐阅读