python - 谷歌趋势分类搜索
问题描述
我正在尝试根据以下链接中的此列表使用 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
解决方案
您可以通过 kw_list 数组中的空字符串类别进行搜索:
keywords = ['']
pytrend.build_payload(kw_list=[''], cat=47,
timeframe='today 3-m', geo='FR', gprop='')
data = pytrend.interest_over_time()
推荐阅读
- css - 在右侧显示嵌套组件,在左侧显示父级
- php - 如何用新的自建php加载数据
- javascript - 将值从数据传递到变量
- svg - 所有 fillTexted 文本都挤在 HTML5 画布中的一个位置
- ios - iOS 在没有远程服务器的情况下实现 NETunnelProviderProtocol
- java - 有没有办法让我重新输入错误的输入?
- javascript - javascript验证html注册表,但没有响应
- python - 如何在python中循环block_blob_service.copy_blob
- visual-studio-code - VS Code - 使用自动换行,使“在上方/下方添加光标”选择下一个“真实”行
- c - 如何正确使用 fgets() 和 strncmp() 函数?