Python 3 Script to Scrape Google Trends Data Using pytrends Library Full Project For Beginners

 

Welcome folks today in this blog post we will be scraping google trends data in python using pytrends library . All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to install the below package using the pip command as shown below

 

 

pip install pytrends

 

 

After installing this library you need to make an app.py file and copy paste the following code

 

 

search keywords

 

 

app.py

 

 

from pytrends.requests import Trendreq

pytrends = TrendReq(hl='en-US', tz = 360)

keyword_list = ['Machine Learning','Python','Linear Regression']
pytrends.build_payload(keyword_list, cat=0, timeframe='today 5-y', geo='', gprop='')

 

See also  Python 3 Datetime Library Script to Convert Current Date Time to Timezone Full Project For Beginners

 

 

Filter Searches based on region

 

 

# Interest by Region
df = pytrends.interest_by_region(resolution='COUNTRY')
print(df.head(10))
df = df.reset_index()
df.plot(x="geoName", y="Machine Learning", figsize=(120, 10), kind ="bar")

 

 

 

Trending searches

 

 

#trending searches
df = pytrends.trending_searches()
print(df.head())

 

 

Related queries

 

 

#related topics
pytrends.build_payload(kw_list=["Machine Learning"])
df = pytrends.related_topics()
print(df['Machine Learning']['top'])

 

Leave a Reply