Skip to main content

 

Python Script to search for YouTube Data trends

R. Eric Kiser

As a subject matter expert, I wanted to gain insight into the topics that my readers and students are interested in. Given the increasing popularity of video platforms such as YouTube, I decided to use a Python script to pull data from Google Trends on a specific topic of interest, “hacking.” This script allows me to understand the current trends and popular search queries in the field, and tailor my content to align with the needs and interests of my audience. Below is the simple script that I created. I tend to do more with the project but that is for another day.

import requests
from pytrends.request import TrendReq

# create a new instance of the pytrends class
pytrend = TrendReq()

# prompt for keyword
keyword = input("Enter a keyword to search for data trends: ")

# set the parameters for the trend search
kw_list = [keyword]
timeframe = "today 1-m"

# get the trends
pytrend.build_payload(kw_list, cat=0, timeframe=timeframe, geo='', gprop='youtube')
trends = pytrend.interest_over_time()

# get the most searched queries
related_queries = pytrend.related_queries()

# print the trends
print(trends)

# print the most searched queries
print(related_queries)

The script is written in python and uses the pytrends library to interact with Google Trends and retrieve data. Making the task a very easy one! Of couse when you are dealing with grabbing data from the web you need to import the requests library. We don’t want to slow our script down so we will add the TrendReq class from the pytrends library to speed up the process. Then, an instance of the TrendReq class is created, and it's stored in the variable pytrend.

Next, the script prompts the user to enter a keyword to search for data trends. The keyword entered by the user is stored in the variable keyword.

Once a keyword is typed and enter is pressed, the parameters are set for the trend search. It creates a list of keywords, in this case, it’s a single keyword, and stores it in the variable kw_list. It also sets the time frame for the search, in this case, it's for the last month, stored in the variable timeframe.

The script then uses the build_payload method of the pytrend object, which takes the keyword list and the other parameters as inputs, and it grabs the trends related to the keywords searched in youtube. This is done by passing the gprop='youtube' parameter to the build_payload method. The script then stores the returned data in the variable trends and prints the trends in the console.

You can run this script in PowerShell or any other CLI. However, be sure to have the dependencies.

The End Result in PowerShell

Comments

Popular posts from this blog

  Cyber Incident Response Workflow Diagraming Tools R. Eric Kiser There are several diagram drawing tools available on the market today that can be explored. Two very common drawing tools, Microsoft Visio and Draw.io tend to dominate the arena. Draw.io is a free, web-based diagramming software that allows users to create a variety of diagrams, including flowcharts, mind maps, network diagrams, and more. It is web application or as a standalone desktop application for multiple operating systems. Draw.io provides a range of templates and shapes to help users create professional-looking diagrams quickly and easily. It also has a range of collaboration features, including the ability to share diagrams and work on them with others in real-time. Draw.io supports a number of file formats, including .png, .svg, .pdf, and .xml, and can be integrated with other applications through its API. Microsoft Visio is very similar to Draw.io but is the proprietary and a part of the Micr...
  Vulnerability Identification Techniques R. Eric Kiser Vulnerability detection can often be automated through the use of tools such as vulnerability scanners. While these tools can be useful, it is important for organizations not to rely solely on automated techniques and to also incorporate more comprehensive methods in their vulnerability detection efforts. Failing to do so could result in the organization missing vulnerabilities that could potentially lead to data breaches. There are a number of methods that can be employed to identify vulnerabilities in target systems Penetration Tests A penetration test, also known as a pen test, is a simulated cyber attack on a computer system, network, or web application to test its defenses and identify vulnerabilities that an attacker could exploit. This is much more than just a scan as the pen tester intends to find a method of getting foothold on your internal network or sensitive data by acting as a real attacker would. T...