概述

pytrends 函式庫中的 multirange_interest_over_time() 函數允許您擷取特定關鍵字在多個時間範圍內的興趣。透過分析這些資料,您可以洞察關鍵字在不同時期內興趣的演變情況,從而為內容策略和行銷工作做出明智的決策。

在本教學中,我們將介紹:

  1. 匯入必要的函式庫
  2. 設定 pytrends 請求
  3. 建立時間範圍清單
  4. 擷取多時間範圍的隨時間變化興趣資料
  5. 分析結果

建立時間範圍清單

首先,我們需要建立一個時間範圍清單,用於分析關鍵字的興趣。在此範例中,我們將建立一個包含兩個時間範圍的清單

time_ranges = [
    '2022-09-04 2022-09-10',
		'2022-09-18 2022-09-24',
]

擷取多時間範圍的隨時間變化興趣資料

接下來,我們需要匯入必要的函式庫,設定 pytrends 請求,並擷取關鍵字和時間範圍的多時間範圍隨時間變化興趣資料。

from pytrends.request import TrendReq

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

# Define the list of keywords
keywords = ['pizza', 'bagel']

# Build the payload
pytrends.build_payload(keywords, timeframe=time_ranges)

# Retrieve multi-range interest over time data
interest_over_time_data = pytrends.multirange_interest_over_time()

這將返回一個字典,其中包含關鍵字在指定時間範圍內的隨時間變化興趣資料。

分析結果

現在,我們可以分析多時間範圍的隨時間變化興趣資料,以了解關鍵字在不同時期的表現和受歡迎程度。

# Display the interest over time data
print(interest_over_time_data)

這將顯示每個時間範圍的隨時間變化興趣資料,為我們關鍵字在不同時期的表現和受歡迎程度提供寶貴的洞察。

結論

在本文中,我們示範了如何使用 pytrends 函式庫中的 multirange_interest_over_time() 函數分析特定關鍵字在多個時間範圍內的興趣。透過分析這些資料,您可以獲得更全面的趨勢視角,並了解關鍵字在不同時期內興趣的演變情況。這些資訊可以幫助您就內容策略、行銷工作甚至產品開發做出明智的決策。善用多時間範圍的隨時間變化興趣分析,您可以保持競爭優勢,並確保您的內容和產品始終與目標受眾相關且具有吸引力。


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

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