gpt4 book ai didi

python - 循环遍历子字符串的所有注释

转载 作者:太空宇宙 更新时间:2023-11-03 14:38:08 25 4
gpt4 key购买 nike

我正在编写一个程序,该程序将检查包含艺术家姓名的字符串列表,并将其与 Reddit 提交的所有评论进行比较。它在找到一个匹配项后停止或根本不起作用(即使使用简单的测试字符串),您能指出该错误吗?包括不包括身份验证的 Reddit 部分。

submission = reddit.submission(id='75lnoo') # Topic about Eminem, lots of mentions of him
submission.comments.replace_more(limit=0) # Stores all the comments
comments = submission.comments.list()
artists_list = ['Eminem', 'Drake'] # Sample list
for comment in comments:
for artist in artists_list:
if artist.lower() in comment.body.lower():
print(comment.permalink() + ' - ' + artist)

当应该有大量匹配项时,只会打印一件事

/r/Music/comments/75lnoo/eminem_rips_donald_trump_in_bet_hip_hop_awards/do894hp - Eminem

最佳答案

刚刚在我的机器上本地运行代码,我得到了很多 Eminem 的结果,但没有得到 Drake 的结果。我的猜测是,因为这一开始让我感到困惑,所以在第一个结果之后花了一段时间才得到第二个结果。可能是您提前终止了程序,认为所有结果都已打印?

这里直接复制粘贴:

 import praw

reddit = praw.Reddit(client_id = '',
client_secret= '',
user_agent= '',
username = '',
password = '')

submission = reddit.submission(id='75lnoo')
submission.comments.replace_more(limit=0) # Stores all the comments
comments = submission.comments.list()
artists_list = ['Eminem', 'Drake'] # Sample list
print(artists_list)
for comment in comments:
for artist in artists_list:
if artist.lower() in comment.body.lower():
print(comment.permalink() + ' - ' + artist)

关于python - 循环遍历子字符串的所有注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46759912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com