Back to articles
How to Scrape YouTube: Videos, Comments, and Channel Analytics
How-ToSystems

How to Scrape YouTube: Videos, Comments, and Channel Analytics

via Dev.to Tutorialagenthustler

YouTube is a goldmine of data for market researchers and content creators. From video metadata to channel performance metrics, there's enormous value in structured YouTube data. Using the YouTube Data API import requests class YouTubeScraper : def __init__ ( self , api_key ): self . key = api_key self . base = ' https://www.googleapis.com/youtube/v3 ' def search ( self , query , max_results = 50 ): resp = requests . get ( f ' { self . base } /search ' , params = { ' part ' : ' snippet ' , ' q ' : query , ' type ' : ' video ' , ' maxResults ' : min ( max_results , 50 ), ' key ' : self . key }) return [{ ' id ' : i [ ' id ' ][ ' videoId ' ], ' title ' : i [ ' snippet ' ][ ' title ' ], ' channel ' : i [ ' snippet ' ][ ' channelTitle ' ], ' published ' : i [ ' snippet ' ][ ' publishedAt ' ] } for i in resp . json (). get ( ' items ' , [])] def get_stats ( self , video_ids ): resp = requests . get ( f ' { self . base } /videos ' , params = { ' part ' : ' statistics ' , ' id ' : ' , ' . join

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
2 views

Related Articles