PRAW:从提交中获得有限数量的新评论

2024-05-03 10:40:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图编写代码来存储一个变量从post提交到文件的注释量。我的代码以其当前形式工作,但它总是返回相同的注释。换言之,我可以运行它的时间间隔和较新的评论将不会显示。我试过跟踪this页面和其他各种站点,但找不到任何有关此的信息。你知道吗

非常感谢您的帮助!你知道吗

post = reddit.submission(url=link)

fileName = "out/" + platform.lower() + ".txt"
file = open(fileName, 'w+')

for top_level_comment in post.comments:
    # Get comment
    try:
        body = top_level_comment.body   
        # Parse each line of comment
        for line in body.splitlines():
            file.write(line + "\n") 
    except:
        continue

Tags: 文件代码infor间隔topline时间
1条回答
网友
1楼 · 发布于 2024-05-03 10:40:23

答案很简单:

post.comment_sort = 'new'

这不是在原始的PRAW注释文档中,而是在here中找到的。你知道吗

相关问题 更多 >