DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Respecting robots.txt in Web Scraping
  • How to Achieve More Accurate Data Extraction From Invoices
  • 10 Predictions Shaping the Future of Web Data Extraction Services
  • What Is Web Scraping and Why Do Software Developers Use It?

Trending

  • Your AI Is Not Failing, Your Context Is
  • Getting Started With GitHub Copilot CLI for Coding Tasks
  • Conversational Risk Accumulation: Stateful Guardrails Beyond Single-Turn LLM Checks
  • Grok AI API Tutorial: Chat, Image, Video, Tool Calling, and Web Search
  1. DZone
  2. Data Engineering
  3. Data
  4. SerpApi YouTube Data Extraction Tool

SerpApi YouTube Data Extraction Tool

YouTube data has become a major part of machine learning and data analytics. Here's how to use SerpApi to extract YouTube data and query it for analysis.

By 
Charles Mabwa user avatar
Charles Mabwa
·
Jan. 03, 22 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
1.5K Views

Join the DZone community and get the full member experience.

Join For Free

With many people shifting to digital online broadcasting, the platform has grown exponentially. YouTube data has become a major part of the analysis in machine learning and data analytics. Using SerpApi, we will extract YouTube data and query it for analysis.

Prerequisites

The product is easy to use and flexible to tailor across multiple YouTube content depending on the field of interest. However, one will require a mid-level knowledge and understanding of:

1. Python 

2. VS code and/or Jupyter Notebook

Tool

To have access to the general tool, go to the YouTube Search API. The below tool has been tailored to extract video results based on searches of desired facets of the data analytics, data science, and data engineers tools:

Properties files
 
import pandas as pd
from serpapi import GoogleSearch
import json

api_key =  "serp_api_key"
engine_search = "youtube"

#data analysis tools:
code_langs = [
    {"name":"engine", "query":"sql"},
    {"name":"engine", "query":"excel"},
    {"name":"engine", "query":"tableau"},
    {"name":"engine", "query":" microsoft azure"},
    {"name":"engine", "query":"amazon web services"},
    {"name":"engine", "query":"r programming"}
    #{"name":"engine", "query":"name_of_product"}   
]

data_vids = pd.DataFrame([])

for lang in code_langs:
    params = {
        lang['name']:engine_search, 
        "search_query": lang['query'],
        "api_key": api_key
    }
    
    search = GoogleSearch(params)
    results = search.get_dict()
    playlist_results = results['video_results']
    data_vids = data_vids.append(pd.json_normalize(playlist_results), ignore_index = True)
    data_vids.to_csv('code_languages.csv')

The tool uses pandas and SerpApi libraries. One is required to have a basic familiarity with the two. In case you are beginning to use the product and are new to python, it is possible that you should first install the required libraries using conda install or pip install.

The code_langs is a tailored list of parameters to be looped over and desired video results appended in the data frame data_vids. For example:

Properties files
 
{"name":"engine", "query":" microsoft azure"},

Using for loop the tool will return microsoft azure content from YouTube. This will be the case for all the queried lists in the code_langs until all the desired videos are appended.

The data is then stored in a CSV file, find the CSV file here

Data

The data extracted has 13 columns. The first 10 are the essential columns with variables that could trigger an analysis.

Properties files
 
position_on_page	title	link	published_date	views	length	description	extensions	channel.name	channel.link	channel.verified	channel.thumbnail	thumbnail.static	thumbnail.rich

These variables include:

a. position on the page: This is the position of the specific video upon the search of a data analytics, data science, or engineering tool.

b. title: The title of the video. This tells what the video is all about.

c. published_date: The date the video was uploaded on YouTube.

d. views: The number of people who have watched the video.

e. length:This tells the duration it takes to watch the video.

f. channel.name: The channel from which a video was retrieved. 

To further know how to extract channel details, visit Channel Results 

The complete code to the tool can be found in this Github Repo. 

YouTube Search API documentation: https://serpapi.com/youtube-search-api

You can also contribute to our user forum here: https://forum.serpapi.com/

Data (computing) Data extraction

Published at DZone with permission of Charles Mabwa. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Respecting robots.txt in Web Scraping
  • How to Achieve More Accurate Data Extraction From Invoices
  • 10 Predictions Shaping the Future of Web Data Extraction Services
  • What Is Web Scraping and Why Do Software Developers Use It?

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook