【发布时间】:2021-12-26 17:51:25
【问题描述】:
“文本”字符串包含 youtube 视频的字幕。如何将这些字幕放在每个视频的单独列表中。
videos = get_channel_videos(channel_id)
video_ids = [] # list of all video_id of channel
for video in videos:
video_ids.append(video['snippet']['resourceId']['videoId'])
for video_id in video_ids:
try:
responses = YouTubeTranscriptApi.get_transcript(
video_id, languages=['en'])
print('\n'+"Video: "+"https://www.youtube.com/watch?v="+str(video_id)+'\n'+'\n'+"Captions:")
for response in responses:
text = response['text']
print(text)
except Exception as e:
print(e)
【问题讨论】:
标签: python youtube-api