6/11/18

Web Scrape YouTube channel for video info and a table of contents using Python 3.6 and Beautiful Soup (V1.1)


THIS TECHNIQUE NO LONGER WORKS!
I will post an update in the future with code that using the Goggle API.

I have a YouTube channel for my videos to teach programming and needed to create a nice table of contents for a web page.

YouTube always list the videos and playlists with a lot of graphics and thumbnail images which look nice, but it does not fit much on a page for reference.

I tried to use write a program using their API, but decided it was better to try 'screen scraping' or 'web scraping'. This is a technique that is used to get information out of web pages.

I ended up writing a python program. Since many sites do not like scrapping, I checked the User Terms Contract for YouTube, and it is OK as long as it is as slow as a human.

I walk through version 1.0 of the code at my YouTube video @ https://youtu.be/NvxAhUkVgHU

Also please subscribe to my YouTube channel

I wanted a program that would output a CSV file to import to a spreadsheet or DB and a HTML file providing a table of contents to all the videos on the channel that I could copy to my blog.

I decided to pull the following data for the CSV file:

  • channel name
  • section name 
  • playlist name 
  • video title
  • video link
  • video time length
  • number of views
  • publication date
  • number of likes
  • number of dislikes
  • video description


I have embedded a gist here that you can see and get the code from:








You need python 3.6 or greater and just need to change the channel name near the top of the program.
Then run it to create the CSV and HTML file in the current run directory.

If you only need the HTML, json, or CSV file, see the if __name__ == '__main__' section and write an driver py program with imports like run_json.py example.

No comments:

Post a Comment

Please comment or give suggestions for follow up articles