google trend データの収集

(1)python を導入 参考:https://qiita.com/yuta_h3/items/2988c4d0811bf8c344c0

git clone git://github.com/yyuu/pyenv.git ~/.pyenv

~/.bash_profile に以下を書きこむ

export PYENV_ROOT="${HOME}/.pyenv"
if [ -d "${PYENV_ROOT}" ]; then
export PATH=${PYENV_ROOT}/bin:$PATH
eval "$(pyenv init -)"
fi

設定の読み込み

source ~/.bash_profile

インストールできる一覧を確認

pyenv install --list

バージョンを指定してインストール

pyenv install 3.6.3

そのディレクトリ以下でバージョンをデフォルトに。

pyenv local 3.6.3

(2)pytrendの導入
pytrends でできる。

pip install pytrends

あとは、git の exampleをみるとOK

*日本語をやるときは、ロケールに注意。プリントできなくてとまる。
*URLエンコードは必要なし。

#--*-- encode: utf-8 --*--
from pytrends.request import TrendReq
import sys
# Login to Google. Only need to run this once, the rest of requests will use the same session.
pytrend = TrendReq()


pytrend.build_payload(kw_list=[u'駅', 'bagel'])
# Interest Over Time
interest_over_time_df = pytrend.interest_over_time()
print(interest_over_time_df)
~