【发布时间】:2022-01-05 12:15:05
【问题描述】:
我正在尝试获取特定 Youtube 视频的所有 cmets。 我写了以下代码:
#storing all the comments in a list (l)
def video_comments(url):
# empty list for storing reply
replies = []
# creating youtube resource object
youtube = build('youtube', 'v3',
developerKey=api_key)
# retrieve youtube video results
video_response=youtube.commentThreads().list(
part='snippet,replies',
videoId=url
).execute()
for item in video_response['items']:
# Extracting comments
comment = item['snippet']['topLevelComment']['snippet']['textDisplay']
# counting number of reply of comment
replycount = item['snippet']['totalReplyCount']
# if reply is there
if replycount>0:
# iterate through all reply
for reply in item['replies']['comments']:
# Extract reply
reply = reply['snippet']['textDisplay']
# Store reply is list
replies.append(reply)
comment = remove_URL(comment)
# print comment with list of reply
l.append(comment)
for resp in replies:
resp = remove_URL(resp)
# print comment with list of replyprint(resp, replies, end = '\n\n')
l.append(comment)
# empty reply list
replies = []
video_comments(n)
但是,即使该视频有数十万个 cmets,以下代码也只能获取 20-25 cmets。
【问题讨论】:
标签: python youtube youtube-api youtube-data-api