youtube数据api注释分页

2024-10-01 07:46:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有点纠结于在youtube视频上迭代所有评论的语法。我使用的是python,并没有找到关于GetYouTubeVideoCommentFeed()函数的文档。在

我真正想做的是搜索视频的所有评论,寻找一个单词的实例,并增加一个计数器(最终评论将被打印出来)。它对返回的25个结果起作用,但我需要访问其余的注释。在

import gdata.youtube
import gdata.youtube.service

video_id = 'hMnk7lh9M3o'
yt_service = gdata.youtube.service.YouTubeService()    
comment_feed = yt_service.GetYouTubeVideoCommentFeed(video_id=video_id)
for comment_entry in comment_feed.entry:
 comment = comment_entry.content.text
 if comment.find('hi') != -1:
  counter = counter + 1

print "hi: "
print counter

除了video_id之外,我还试图设置GetYouTubeVideoCommentFeed()start_index,但它不喜欢这样。在

我有什么遗漏吗?在

谢谢! 史蒂夫


Tags: importid视频youtubevideofeedservicecounter
2条回答

下面是相同的代码片段:

# Comment feed URL
comment_feed_url = "http://gdata.youtube.com/feeds/api/videos/%s/comments"

''' Get the comment feed of a video given a video_id'''        
def WriteCommentFeed(video_id, data_file):  
    url = comment_feed_url % video_id
    comment_feed = yt_service.GetYouTubeVideoCommentFeed(uri=url)

    try:
        while comment_feed:

            for comment_entry in comment_feed.entry:
                print comment_entry.id.text
                print comment_entry.author[0].name.text
                print comment_entry.title.text
                print comment_entry.published.text
                print comment_entry.updated.text
                print comment_entry.content.text

            comment_feed = yt_service.Query(comment_feed.GetNextLink().href) 

    except:
            pass

知道怎么做。您可以传递一个URL,而不是向GetYouTubeVideoCommentFeed函数传递一个video_id。您可以通过更改URL参数来遍历注释。在

但一定有API限制;我只能访问视频中最后1000条评论。在

相关问题 更多 >