1

我正在尝试扫描特定的 subreddit,以查看评论在热门提交中出现的次数。

我无法得到任何迹象表明它实际上正在阅读消息,因为它根本不会打印消息的正文。 注意: sr = subreddit 短语 = 正在寻找的短语

我对 praw 和 python 还是很陌生(只是在最后一个小时才学会),但我在 c 方面有相当多的经验。

任何帮助,将不胜感激。

    submissions = r.get_subreddit(sr).get_top(limit=1)
    for submission in submissions:
        comments = praw.helpers.flatten_tree(submission.replace_more_comments(limit=None, threshold=0))
        for comment in comments:
            print(comment.body.lower())
            if comment.id not in already_done:
                if phrase in comment.body.lower():
                    phrase_counter = phrase_counter + 1
4

1 回答 1

1

Submission.replace_more_comments返回未被替换的MoreComment对象列表。因此,如果您使用它调用它,那么它将返回一个空列表。请参阅文档字符串。下面是如何同时使用和的完整示例。有关更多信息,请参阅我们文档中的评论解析页面。limit=Nonethreshold=0replace_more_commentsreplace_more_commentsflatten_tree

import praw

r = praw.Reddit(UNIQUE_AND_DESCRIPTIVE_USERAGENT_CONTAINING_YOUR_REDDIT_USERNAME)
subreddit = r.get_subreddit('python')
submissions = subreddit.get_top(limit=1)
for submission in submissions:
    submission.replace_more_comments(limit=None, threshold=0)
    flat_comments = praw.helpers.flatten_tree(submission.comments)
    for comment in flat_comments:
        print(comment.body)
于 2014-03-06T20:16:38.363 回答