我尝试编写代码以将变量数量的新条评论从帖子提交到文件。我当前形式的代码有效,但它总是返回相同的注释。换句话说,我可以分开运行它,并且不会显示更新的评论。我尝试关注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