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.
python GET_YouTube_Video_info.py https://youtu.be/9bZkp7q19f0
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
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