【问题标题】:youtube data api comment pagingyoutube 数据 api 评论分页
【发布时间】:2010-12-26 11:13:12
【问题描述】:

我在遍历 youtube 视频上的所有 cmets 的语法上有些吃力。我正在使用 python,但几乎没有找到关于 GetYouTubeVideoCommentFeed() 函数的文档。

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

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,但它不喜欢那样。

我有什么遗漏吗?

谢谢! 史蒂夫

【问题讨论】:

    标签: python youtube youtube-api


    【解决方案1】:

    了解如何做到这一点。您可以将 URL 传递给它,而不是将 video_id 传递给 GetYouTubeVideoCommentFeed 函数。您可以通过更改 URL 参数来遍历 cmets。

    但必须有 API 限制;我只能访问视频中的最后 1000 个 cmets。

    【讨论】:

      【解决方案2】:

      这是相同的代码sn-p:

      # 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
      

      【讨论】:

        猜你喜欢
        • 2020-06-27
        • 2013-09-20
        • 2021-04-26
        • 2013-11-21
        • 1970-01-01
        • 2022-01-05
        • 2011-03-03
        • 1970-01-01
        • 2015-07-10
        相关资源
        最近更新 更多