Get information about videos uploaded to YouTube [Python]

YouTube video information (Title, description) I would like to get. 2016/02/07, it works with the current specifications. Will it become unusable if the specifications change in the future? It may be.

First of all, bs4, which is convenient for scraping, is used, so if you have not installed it, please install it. It will not work without it. First of all, the tags I could confirm Title, description watch-title, eow-description was. It won't change right now.

Input sample

python GET_YouTube_Video_info.py https://youtu.be/9bZkp7q19f0

Output sample

PSY - GANGNAM STYLE(강남스타일) M/V
PSY - DADDY(feat. CL of 2NE1) M/V @ https://youtu.be/FrG4TEcSuRgPSY - 나팔바지(NAPAL BAJI) M/V @ https://youtu.be/tF27TNC_4pcPSY - 7TH ALBUM '칠집싸이다' on iTunes @ http://smarturl.it/PSY_7THALBUMPSY - GANGNAM STYLE(강남스타일) on iTunes @ http://smarturl.it/PsyGangnam#PSY #싸이 #GANGNAMSTYLE #강남스타일More about PSY@http://www.psypark.com/http://www.youtube.com/officialpsyhttp://www.facebook.com/officialpsyhttp://twitter.com/psy_oppahttp://iTunes.com/PSYhttp://sptfy.com/PSYhttp://weibo.com/psyoppahttp://twitter.com/ygent_official

code

GET_YouTube_Video_info.py


#coding: utf-8

import csv, sys, re
import urllib2 as request
#Installation required: bs4
from bs4 import BeautifulSoup


class Main:
    def __init__(self, url):
        self.url = url
    def request_(self):
        watch_title_list = []
        eow_description_list = []

        response = request.urlopen(self.url)
        body = response.read()
        soup = BeautifulSoup(body)

        watch_titles  = soup.find_all(attrs={'class': 'watch-title '})
        eow_descriptions = soup.find_all('p', {'id': 'eow-description'})

        for watch_title, eow_description in zip(watch_titles, eow_descriptions):
            watch_title_list.append(watch_title['title'])
            eow_description_list.append(eow_description.text)

        return watch_title_list, eow_description_list


if __name__ == '__main__':
    Main = Main(sys.argv[1])
    res_title, res_description = Main.request_()
    for title, description in zip(res_title, res_description):
        print title
        print description

Recommended Posts

Get information about videos uploaded to YouTube [Python]
[Python] I tried to get various information using YouTube Data API!
Python script to get note information with REAPER
Get YouTube Comments in Python
Get Youtube data with python
Get Alembic information with Python
Call github api in python to get pull request information
Link to get started with python
How to get the Python version
Python version to get unused ports
Get weather information with Python & scraping
PhytoMine-I tried to get the genetic information of plants with Python
Get property information by scraping with python
Search and play YouTube videos in Python
How to get a stacktrace in python
Get Youtube data in Python using Youtube Data API
How to download youtube videos with youtube-dl
How to download youtube videos using pytube3
[Python] Get Python package information with PyPI API
I tried to get the movie information of TMDb API with Python
Try to download Youtube videos using Pytube
Automatically search and download YouTube videos with Python
[Python] Get all comments using Youtube Data API
Use the MediaWiki API to get Wiki information
[Bash] Use here-documents to get python power from bash
I tried to get CloudWatch data with Python
Get note information using Evernote SDK for Python 3
Post youtube soaring title to twitter with python3
Get pointers to struct members in Python ctypes
How to get dictionary type elements of Python 2.7
Get CPU information of Raspberry Pi with Python
How to get the files in the [Python] folder
Get BTC / JPY board information from Python --bitflyer
What to do to get google spreadsheet in python
A layman wants to get started with Python
Use os.getenv to get environment variables in Python
About python slices
About python comprehension
Updated to Python 2.7.9
About Python tqdm.
About python yield
About python, class
Get information equivalent to the Network tab of Chrome developer tools with Python + Selenium
About python inheritance
About python, range ()
A story about a Python beginner trying to get Google search results using the API
About python decorators
About python reference
About Python decorators
[Python] About multi-process
"Backport" to python 2
Think about how to program Python on the iPad
[First API] Try to get Qiita articles with Python
Get media timeline images and videos with Python + Tweepy
How to get the number of digits in Python
I tried to get started with blender python script_Part 01
I tried to get started with blender python script_Part 02
Python beginners talk about how to remember this much
Get comments on youtube Live with [python] and [pytchat]!
How to get mouse wheel verdict with Python curses
[Python-pptx] Output PowerPoint font information to csv with python