Skip to content

[Python] Use pytrends package to get the Google Trends search results

Google Trends is an online search trends service provided by Google, it can confirm in front of you which keywords are popular recently.

But sometimes, I'm lazy even to open web pages, so I once thought about build a special crawler program to handle this matter, while I was researching this matter, I found this useful Python package: pytrends.

It is an unofficial support API, basically for packaging the crawler I want to make, so I am grateful to use it.

The detailed introduction can be viewed at PyPI: https://pypi.org/project/pytrends/1.1.3/

The following briefly introduces how to use the pytrends package in Python!


How to use pytrends package

If you use it at the first time, you can use the following command to install:

sudo pip3 install pytrends


The use way is just like the following example:

from pytrends.request import TrendReq
from pprint import pprint


pytrend = TrendReq(hl='en-US', tz=360)
keywords = ['Python', 'Java', 'C++']
pytrend.build_payload(
     kw_list=keywords,
     cat=0,
     timeframe='today 1-m',
     geo='TW',
     gprop='')

pprint(pytrend.interest_over_time())



Output:

It can be seen from the results that if you look at Taiwan, the search for C++ is still quite high!

Leave a Reply