【问题标题】:Get topic id from Google Trends for a topic name using Python使用 Python 从 Google 趋势中获取主题名称的主题 ID
【发布时间】:2019-05-30 17:38:06
【问题描述】:

使用 Python,我正在尝试从 Google 趋势中抓取“主题”(而不是“搜索词”)的数据。

我目前正在使用pytrends 模块,但除非您知道topic_id,否则(目前)似乎无法抓取主题而不是搜索词。

例如如果你想抓取topic_name“假日”的数据,你可以使用topic_id/m/03gkl进行搜索,但前提是你知道那是topic_id

我有一个主题名称列表。我想要一个相应的主题 ID 列表。我怎样才能做到这一点?

【问题讨论】:

    标签: python google-trends


    【解决方案1】:

    看来我没有正确阅读pytrends 文档,并且可以获取主题ID:

    from pytrends.request import TrendReq
    pytrends = TrendReq(hl='en-US', tz=360)
    suggs = pytrends.suggestions("iron")
    print(suggs)
    
    [{'mid': '/m/025rw19', 'title': 'Iron', 'type': 'Chemical element'},
     {'mid': '/m/04jphh9', 'title': 'Clothes iron', 'type': 'Topic'},
     {'mid': '/m/0b6l369', 'title': 'Loha', 'type': '1987 film'},
     {'mid': '/m/03cld36', 'title': 'Iron', 'type': 'Golf'},
     {'mid': '/m/0281ql7', 'title': 'Ferric', 'type': 'III'}]
    

    从上面,很容易提取出topic id。

    【讨论】:

      猜你喜欢
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-19
      • 2016-10-21
      相关资源
      最近更新 更多