我正在使用此代码,但它不适用于API v2,请提供用于提取youtube注释的代码。
import gdata.youtube.service
yts = gdata.youtube.service.YouTubeService()
ytfeed = yts.GetYouTubeVideoCommentFeed(video_id="pXhcPJK5cMc")
comments = [comment.content.text for comment in ytfeed.entry]
要使用YouTube API v.3提取YouTube视频评论,您需要一些Python代码,如下所示:
def get_video_comments(service, **kwargs):
comments = []
results = service.commentThreads().list(**kwargs).execute()
while results:
for item in results['items']:
comment = item['snippet']['topLevelComment']['snippet']['textDisplay']
comments.append(comment)
# Check if another page exists
if 'nextPageToken' in results:
kwargs['pageToken'] = results['nextPageToken']
results = service.commentThreads().list(**kwargs).execute()
else:
break
return comments
有关此代码的详细信息以及如何使用YouTube API使用关键字搜索视频,然后将注释保存到CSV文件,您可以查看本教程:https://python.gotrained.com/youtube-api-extracting-comments/