【发布时间】:2021-04-18 18:48:24
【问题描述】:
我不久前完成了我的项目,该项目根据 YouTube 上的关键字对视频进行了 cmets,它将使用随机库选择随机评论。 当“随机”将 cmets 添加到 YouTube视频。我开始认为我可能需要提高随机性,事实是 它选择了第 4 条评论(共 9 条)7 次,第 9 条评论 3 次。这两个 结果一个接一个地发生,换句话说,它连续发送相同的消息 当它意味着随机选择而不是重复时。 有什么办法可以增加随机性吗?如果你知道,请告诉我,我将不胜感激!
PS:这更多的是阻止它在 YouTube 上重复同一句话。
代码:
if __name__ == "__main__":
from googleapiclient.errors import HttpError
import random
import time
import sys
# Comments are getting loaded
comments = load_comments('Comments.txt')
# Getting the number of comments you want to add
number_of_comments = int(input('Enter the number of comments: '))
count, cycle, videoid_store = 0, 1, []
# Getting the keyword
keyword = input('Enter the Keyword: ')
# This loop keeps running until all comments have been added
youtube = authentication()
while count < number_of_comments:
print("Searching for videos .. (Cycle:%d)" %cycle)
time.sleep(10)
random.shuffle(comments)
【问题讨论】:
标签: python python-3.x random youtube youtube-api