Ste*_* S. 4 python youtube youtube-api
我正在努力学习迭代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
Run Code Online (Sandbox Code Playgroud)
我试图设置start_index的GetYouTubeVideoCommentFeed()除了video_id,但它不喜欢那个.
有什么我想念的吗?
谢谢!史蒂夫
这是相同的代码片段:
# 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1712 次 |
| 最近记录: |