我正在使用praw从reddit线程中抓取信息。我可以使用r.get_submission(thread).comments
在线索中给我所有的评论,但是现在我想遍历所有这些评论并获得孩子的评论。在Python中使用Praw获得孩子评论的Reddit
这是我有:
r = praw.Reddit(user_agent="archiver v 1.0")
thread = "https://www.reddit.com/r/AskReddit/comments/4h4o7s/what_do_you_regret_doing_at_university/"
r.login(settings['username'], settings['password'], disable_warning=True)
submission = r.get_submission(thread)
for comment in submission.comments:
#this works, prints out the comments text
print(comment.body)
#now i want to get the child comments that are replied to this comment
commentSubmission = r.get_submission(comment.permalink)
#ideally comments[0] should show me first reply, comments[1] the second. etc
print(commentSubmission.comments[1])
这将引发IndexError: list index out of range
。我使用的试图得到尽可能提交注释的方法,因为它是类同的解决方案,我看到这里的时候,我是研究https://www.reddit.com/r/redditdev/comments/1kxd1n/how_can_i_get_the_replies_to_a_comment_with_praw/
我的问题是:给定一个praw comment
对象,我怎么能遍历所有孩子的评论是答复?我想获得所有直接回复给另一个评论对象的评论。
例如,我在程序的示例线程,则第一个评论是Not going out freshman year
我想得到这样Meh, I never went out at all in college.
和Your story sounds identical to mine