Praw(Reddit API)如何获取超过10层的评论回复
好的,我写了一些代码,理论上应该能正常工作:
def checkComments(comments):
for comment in comments:
print comment.body
checkComments(comment.replies)
def processSub(sub):
sub.replace_more_comments(limit=None, threshold=0)
checkComments(sub.comments)
#login and subreddit init stuff here
subs = mysubreddit.get_hot(limit=25)
for sub in subs:
processSub(sub)
但是,如果有一个评论下面有50个嵌套的回复,像这样:
root comment
-> 1st reply
-> 2nd reply
-> 3rd reply
...
-> 50th reply
那么上面的代码只会打印出:
root comment
1st reply
2nd reply
3rd reply
4th reply
5th reply
6th reply
7th reply
8th reply
9th reply
有没有人知道我怎么才能获取剩下的41层回复?或者这是praw的限制吗?
1 个回答
3
首先,limit
是用来限制结果数量的,而不是结果的层级深度。
不过,这里并不是问题的关键,reddit API 的 morecomments
接口似乎在处理深层嵌套评论时返回了错误的结果。
想了解更多技术细节,可以查看 bug报告 #321。