后下达到你的要求使用Python YouTube API:
from gdata.youtube import service
USERNAME = '[email protected]'
PASSWORD = 'a_very_long_password'
VIDEO_ID = 'wf_IIbT8HGk'
def comments_generator(client, video_id):
comment_feed = client.GetYouTubeVideoCommentFeed(video_id=video_id)
while comment_feed is not None:
for comment in comment_feed.entry:
yield comment
next_link = comment_feed.GetNextLink()
if next_link is None:
comment_feed = None
else:
comment_feed = client.GetYouTubeVideoCommentFeed(next_link.href)
client = service.YouTubeService()
client.ClientLogin(USERNAME, PASSWORD)
for comment in comments_generator(client, VIDEO_ID):
author_name = comment.author[0].name.text
text = comment.content.text
print("{}: {}".format(author_name, text))
不幸的是,API限制了可检索到条目的数量。这就是我,当我尝试了微调的版本,用一只手的错误制作GetYouTubeVideoCommentFeed
URL参数:
gdata.service.RequestError: {'status': 400, 'body': 'You cannot request beyond item 1000.', 'reason': 'Bad Request'}
注意,同样的原则应适用于检索API的其他供稿条目。
如果你想手工工艺GetYouTubeVideoCommentFeed
URL参数,它的格式是:
'https://gdata.youtube.com/feeds/api/videos/{video_id}/comments?start-index={start_index}&max-results={max_results}'
以下限制:start-index <= 1000
和max-results <= 50
。
这回答了[这里](http://stackoverflow.com/questions/10941803/using-youtube-api-to-get-all-comments-from-a-video-with-the-json-feed)使用PHP的解决方案,因为YouTube PHP API有一个允许它的调用。我不认为纯Python的答案就在那里。 –
@KenB我也看到了。这太遗憾了。有问题的视频有9k条评论,我不认为制作360'GetNextLink'是最好的方法。 – TankorSmash
“www.youtube.com/all_comments?v = video_id”网址有一个可解析的评论列表,但这是一个很长的加载时间。假设我可以尝试。 – TankorSmash