概述

pytrends 库中的 related_queries() 函数允许您检索特定搜索词的相关查询。通过分析这些数据,您可以洞察对您的受众重要的问题和主题,帮助您创建更相关和吸引人的内容。

在本教程中,我们将介绍:

  1. 导入必要的库
  2. 设置 pytrends 请求
  3. 检索相关查询数据
  4. 分析结果

检索相关查询数据

首先,我们需要导入必要的库并设置 pytrends 请求。

from pytrends.request import TrendReq

# Set up pytrends request
pytrends = TrendReq(hl='en-US', tz=360)

接下来,我们将使用 build_payload() 函数指定搜索词,然后使用 related_queries() 函数检索相关查询数据。

keywords = ['Python']

# Build payload
pytrends.build_payload(keywords, timeframe='now 7-d', geo='')

# Retrieve related queries data
related_queries = pytrends.related_queries()

这将返回一个字典,其中包含搜索词’Python’在过去7天内的相关查询数据。

分析结果

现在,我们可以分析相关查询数据,以识别内容创作和优化的新机会。

# Extract the related queries for the keyword 'Python'
python_related_queries = related_queries[keywords[0]]['rising']

# Display the top 10 rising related queries
print(python_related_queries.head(10))

这将显示搜索词’Python’的前10个上升相关查询,为您提供有关受众重要问题和主题的宝贵洞察。

结论

在本文中,我们演示了如何使用 pytrends 库中的 related_queries() 函数发现给定搜索词的相关查询。通过分析这些数据,您可以对目标关键词进行深入分析,并发现内容创作和优化的新机会。本教程涵盖了从设置 pytrends 请求到分析结果的整个收集和分析相关查询数据的过程。利用这些洞察,您可以为受众创建更相关和吸引人的内容。


NOTE : pytrends uses an unofficial API. Please use here for issues.

SAMPLE CODE : https://github.com/hobbyworker/google-trend-for-python