Prateek
LowCode Bhai

Follow

LowCode Bhai

Follow

How to get YouTube Channel ID from URL using Python

Prateek's photo
Prateek
·Jan 22, 2023·
How to get YouTube Channel ID from URL using Python

Introduction

As a content creator or marketer, analyzing a YouTube channel's statistics is extremely important. These statistics provide valuable insights into a channel's performance and can help inform decisions on how to improve the content, reach new audiences, and measure the success of marketing campaigns.

One can fetch all such key stats for a YouTube channel from the official API of YouTube. However, you need to have the ID of that channel in order to get the required data from the API.

In this article, we will guide you through the simple process of extracting a YouTube channel ID from its URL, using Python.

Implementation

We will be using two python libraries in this code - requests (version 2.28.2) and bs4 (version 4.6.3)

# import libraries
import requests
from bs4 import BeautifulSoup

# YouTube Channel's URL
url = "https://www.youtube.com/@SonyLIV"

# get html content from the URL
response = requests.get(url)
soup = BeautifulSoup(response.content,'html.parser')

# extract and print channel's ID
print(soup.find("meta", itemprop="channelId")['content'])

That's it! This is how you can get any YouTube channel's ID from its URL and use the ID to fetch more data from YouTube's Data API.

 
Share this