Gather data from Google Trends for examining public interest in the “Unification Church” after the assassination of Shinzo Abe

Jan 15 – Jan 20

The API I used for gathering information
  • pytrends
    • unofficial API of Google Trends makes it easy to gather vast amounts of information from Google search
      • Use keywords I chose when I tried to gather information from Twitter
        • 統一 OR 統一教会 OR 文鮮明 OR 韓鶴子 OR 家庭連合 OR 祝福2世 OR 祝福二世 OR 祝福2世
        • 2世 OR 二世 OR 2世 OR 宗教二世 OR 宗教2世 OR 宗教2世 OR 三世 OR 3世 OR 3世 OR 宗教三世 OR 宗教3世 OR 宗教3世
      • Codes used pytrends are the following:
import pytrends
import matplotlib
import pandas as pd
from matplotlib import pylab as plt
font = {'family' : 'Noto Sans CJK JP'}
matplotlib.rc('font', **font)
import requests
from lxml import etree
from pytrends.request import TrendReq

# API Connection
pytrends = TrendReq(hl='ja=JP', tz=540)
# Set the search keyword
kw_list1 = ['統一教会', '統一協会', '旧統一協会', '旧統一教会']
kw_list2 = ['文鮮明', '韓鶴子', '家庭連合', '祝福二世']
kw_list3 = ['統一', '祝福2世', '祝福2世']

pytrends.build_payload(kw_list1, timeframe='2022-07-07 2023-01-17', geo='JP')
df1 = pytrends.interest_over_time()

pytrends.build_payload(kw_list2, timeframe='2022-07-07 2023-01-17', geo='JP')
df2 = pytrends.interest_over_time()

pytrends.build_payload(kw_list3, timeframe='2022-07-07 2023-01-17', geo='JP')
df3 = pytrends.interest_over_time()

df = pd.concat([df1, df2, df3], axis=1)
df.to_csv("gt-church-20220707-20230117.csv", encoding="shift_jis")
import pytrends
import matplotlib
import pandas as pd
from matplotlib import pylab as plt
font = {'family' : 'Noto Sans CJK JP'}
matplotlib.rc('font', **font)
import requests
from lxml import etree
from pytrends.request import TrendReq

# API Connection
pytrends = TrendReq(hl='ja=JP', tz=540)
# Set the search keyword

kw_list1 = ['2世', '二世', '2世', '宗教2世']
kw_list2 = ['宗教2世', '宗教二世', '3世', '3世']
kw_list3 = ['宗教3世', '宗教3世', '宗教三世', '三世']

pytrends.build_payload(kw_list1, timeframe='2022-07-07 2023-01-17', geo='JP')
df1 = pytrends.interest_over_time()

pytrends.build_payload(kw_list2, timeframe='2022-07-07 2023-01-17', geo='JP')
df2 = pytrends.interest_over_time()

pytrends.build_payload(kw_list3, timeframe='2022-07-07 2023-01-17', geo='JP')
df3 = pytrends.interest_over_time()

df = pd.concat([df1, df2, df3], axis=1)
df.to_csv("gt-gen-20220707-20230117.csv", encoding="shift_jis")
Other parameters I would like to use
  • pytrends.related_queries()
  • pytrends.suggestions(keyword)
Problems
  • Because pytrends send a large number of requests to the Google server, Google frequently restricts my computer’s IP address to protect its server. The error message looks like this:
pytrends.exceptions.ResponseError: The request failed: Google returned a response with code 429.