Python 如何获得Reddit提交';使用API的用户评论?

Python 如何获得Reddit提交';使用API的用户评论?,python,reddit,praw,Python,Reddit,Praw,我可以使用以下代码访问a: hot = praw.Reddit(...).subreddit("AskReddit").hot(limit=10) for post in hot: print(post.title, post.url) Would you watch a show where a billionaire CEO has to go an entire month on their lowest paid employees salary, without access t

我可以使用以下代码访问a:

hot = praw.Reddit(...).subreddit("AskReddit").hot(limit=10)
for post in hot:
  print(post.title, post.url)

Would you watch a show where a billionaire CEO has to go an entire month on their lowest paid employees salary, without access to any other resources than that of the employee? What do you think would happen? https://www.reddit.com/r/AskReddit/comments/f08dxb/would_you_watch_a_show_where_a_billionaire_ceo/
All of the subreddits are invited to a house party. What kind of stuff goes down? https://www.reddit.com/r/AskReddit/comments/f04t6o/all_of_the_subreddits_are_invited_to_a_house/
如何获取特定提交的评论,例如第一个:
https://www.reddit.com/r/AskReddit/comments/f08dxb/would_you_watch_a_show_where_a_billionaire_ceo/
普拉在中有一节回答了这个问题。看

根据链接的文档修改代码

from praw.models import MoreComments

reddit = praw.Reddit(...)

hot = reddit.subreddit("AskReddit").hot(limit=10)
for submission in hot:
    print(submission.title)
    for top_level_comment in submission.comments:
        if isinstance(top_level_comment, MoreComments):
            continue
        print(top_level_comment.body)
这将打印提交的所有顶级评论。请注意,
Comment
类还有其他属性,其中许多属性都有文档记录。例如,要打印用红色圈出的
注释的某些属性,请尝试:

print(comment.author)
print(comment.score)
print(comment.created_utc)  # as a Unix timestamp
print(comment.body)
正如链接文档所示,您可以使用
.list()
方法获取提交中的每条评论:

reddit = praw.Reddit(...)

hot = reddit.subreddit("AskReddit").hot(limit=10)
for submission in hot:
    print(submission.title)
    submission.comments.replace_more(limit=None)
    for comment in submission.comments.list():
        print(comment.author)
        print(comment.score)
        print(comment.created_utc)  # as a Unix timestamp
        print(comment.body)

我相信你所说的“主题”是指服从。代码示例中的每个
i
都是Reddit提交。(顺便说一句,
i
在这里是一个坏名字,因为它通常表示一个“索引”(从0开始计数的数字),这不是您在这里所拥有的)。请参阅,以获取您的问题的答案。如果其他人没有抢先一步,我会在后面写一个更详细的答案。我所说的“主题”是指
https://www.reddit.com/r/AskReddit/comments/f08dxb/would_you_watch_a_show_where_a_billionaire_ceo/
。我不知道reddit的api如何调用它。谢谢。我已经在你以前的邮件中找到了这个链接。有点毛茸茸的树逻辑结构。是的。它反映了Reddit上的接口。大多数评论都有一定数量(可能为零)的回复,此外,可能有也可能没有“更多评论”按钮。如果您想使用堆栈/队列或递归手动遍历树,这是可能的。但是,如果您需要的话,
.list()
方法也有助于获取所有注释。