Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python YouTube Playlist Link Collector
from bs4 import BeautifulSoup
import requests
def getPlaylistLinks(url):
sourceCode = requests.get(url).text
soup = BeautifulSoup(sourceCode, 'html.parser')
domain = 'https://www.youtube.com'
for link in soup.find_all("a", {"dir": "ltr"}):
href = link.get('href')
if href.startswith('/watch?'):
print(link.string.strip())
print(domain + href + '\n')
getPlaylistLinks('Playlist url')
@bytescreator

This comment has been minimized.

Copy link

@bytescreator bytescreator commented Oct 20, 2018

Note That it can only gather 100 vids for large playlists also you need to change the name of the file to run it because it gives an import error if you did not rename it

@ManlyBrucetheThird

This comment has been minimized.

Copy link

@ManlyBrucetheThird ManlyBrucetheThird commented Feb 4, 2019

Can the code be modified to select more than 100 videos? The playlist I'm working with has about 300 and is constantly growing

@PhanTruongT

This comment has been minimized.

Copy link

@PhanTruongT PhanTruongT commented Oct 25, 2019

It can't scrape more than 100 links at a time because of Youtube's infinite scroll. Notice if you go to the playlist link and scroll down, it stops and load the next page. You'll have to use BeautifulSoup in conjunction with Selenium to get more than 100 links.

@dahmadjid

This comment has been minimized.

Copy link

@dahmadjid dahmadjid commented Feb 29, 2020

what do you mean by in conjuction with selenium ? how exactly should you use selenium to solve the infinite scroll problem ?
im working on a playlist with more than 100 and i need to solve this so that i can order the downloaded videos according to the playlist by adding numbers

@Axeltherabbit

This comment has been minimized.

Copy link

@Axeltherabbit Axeltherabbit commented Jul 26, 2020

Made a quick fork https://gist.github.com/Axeltherabbit/5b147d508faf1b5cd735a52bd916b1e4 (No, doesn't solve the 100 video problem)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment