0

I was wondering how to webscrape the title of the first video in an youtube-playlist ?

what I have so far try'd:

import urllib.request
from bs4 import BeautifulSoup

theurl = "https://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj"
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage, "html.parser")

print(soup.findAll("h1",{"class":"title style-scope ytd-video-primary-info-renderer"}))

But it only prints = "[]" as output. Am I doing something wrong here ?

greetings

SLake
  • 24
  • 5
  • 1. you can use YouTube API instead; 2. you can look for the `` tag instead. – Raptor Nov 27 '17 at 01:38
  • @Raptor sorry, but im new to python and just started 20 min ago looking at html in total completly new to programming. How would the code look with the " tag ? I didnt see such kind of tag. thanks for the quick answer – SLake Nov 27 '17 at 01:53
  • Title tag is in the HTML ``, which contains the title of the video in YouTube. – Raptor Nov 27 '17 at 02:28

1 Answers1

0

I did the following:

all = (soup.findAll("span",{"class":"title"}))
for a in all:
    print(a.text)
    break

When I looked in the soup, I could see the playlist has class=title for each song in the list. The output is:

Ed Sheeran - Thinking Out Loud [Official Video]
Nabin
  • 11,216
  • 8
  • 63
  • 98
  • Thank you! With your code as a blueprint il be able to understand whats happening waaay faster :D – SLake Nov 27 '17 at 02:53