遍历子字符串的所有评论
Loop through all comments for a substring
我正在编写一个程序,它会遍历包含艺术家姓名的字符串列表,并将其与 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
的结果和 none 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)
我正在编写一个程序,它会遍历包含艺术家姓名的字符串列表,并将其与 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
的结果和 none 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)