概述

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