def youtube_channel(channel_id):
import xml.etree.ElementTree as ET
import urllib.request
import datetime
url = "https://www.youtube.com/feeds/videos.xml?max-results=50&channel_id=" + channel_id
videos = []
with urllib.request.urlopen(url) as f:
root = ET.parse(f).getroot()
for entry in root.iter('{http://www.w3.org/2005/Atom}entry'):
video = {}
video['id'] = entry.find('{http://www.youtube.com/xml/schemas/2015}videoId').text
video['date'] = datetime.datetime.strptime(entry.find('{http://www.w3.org/2005/Atom}published').text, '%Y-%m-%dT%H:%M:%S+00:00')
video['title'] = entry.find('{http://www.w3.org/2005/Atom}title').text
videos.append(video)
return videos
评论列表
文章目录