How to get comments from videos using YouTube API v3 and Python?

前端 未结 5 1978
陌清茗
陌清茗 2021-02-02 04:40

I\'ve been trying to get comments (both threads and replies) from a given video on YouTube using Python (as an exercise to learn the language).

Based on the examples giv

5条回答
  •  死守一世寂寞
    2021-02-02 04:44

    it seems you are dealing with the same problem i had. Comments your are missing most proabably are hidden behind a comment Thread. Simple solution, after you getting all comment threads id, take each comment thread id and check whether it has hidden comments, if so scrape them. Here is the simple example:

    if (item['snippet']['totalReplyCount']>0):
                res2 = comments_list(youtube, 'snippet', item['id'])
                for item2 in res2['items']:
                    commentL = list()
                    commentL.append(item2['id'])
                    commentL.append(item2['snippet']['authorChannelUrl'])
    
    def comments_list(service, part, parent_id):
        results = service.comments().list(
        parentId=parent_id,
        part=part
      ).execute()
    
        return results 
    

提交回复
热议问题