概述
pytrends 函式庫中的 related_topics() 函數允許您擷取特定搜尋詞的相關主題。透過分析這些資料,您可以發現與目標受眾相關的新關鍵字和創意,幫助您建立有吸引力且切題的內容。
在本教學中,我們將介紹:
- 匯入必要的函式庫
- 設定
pytrends請求 - 擷取相關主題資料
- 分析結果
擷取相關主題資料
首先,我們需要匯入必要的函式庫並設定 pytrends 請求。
from pytrends.request import TrendReq
# Set up pytrends request
pytrends = TrendReq(hl='en-US', tz=360)
接下來,我們將使用 build_payload() 函數指定搜尋詞,然後使用 related_topics() 函數擷取相關主題資料。
keywords = ['Python']
# Build payload
pytrends.build_payload(keywords, timeframe='now 7-d', geo='')
# Retrieve related topics data
related_topics = pytrends.related_topics()
這將返回一個字典,其中包含搜尋詞「Python」在過去 7 天內的相關主題資料。
分析結果
現在,我們可以分析相關主題資料,以識別用於內容策略的新關鍵字和創意。
# Extract the related topics for the keyword 'Python'
python_related_topics = related_topics[keywords[0]]['top']
# Display the top 10 rising related topics
print(python_related_topics.head(10))
這將顯示搜尋詞「Python」的前 10 個上升相關主題,為您提供有關與您的關鍵字相關的新興趨勢的寶貴洞察。
結論
在本文中,我們示範了如何使用 pytrends 函式庫中的 related_topics() 函數調查指定搜尋詞的相關主題。透過探索這些資料,您可以擴展關鍵字研究並發現吸引目標受眾的新機會。本教學涵蓋了從設定 pytrends 請求到分析結果的整個收集和分析相關主題資料的過程。善用這些洞察,您可以為內容策略提供參考並提升您的線上影響力。
NOTE : pytrends uses an unofficial API. Please use here for issues.
SAMPLE CODE : https://github.com/hobbyworker/google-trend-for-python