【发布时间】:2016-05-11 15:31:58
【问题描述】:
我正在使用 praw 从 reddit 线程中抓取信息。我可以使用r.get_submission(thread).comments 给我一个线程中的所有 cmets,但现在我想遍历所有这些 cmets 并获取子 cmets。
这是我所拥有的:
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 对象,我如何遍历所有作为回复的子 cmets?我想获取所有直接回复另一个评论对象的 cmets。
例如,在我的程序中的示例线程中,第一条评论是Not going out freshman year我想得到像Meh, I never went out at all in college.和Your story sounds identical to mine这样的响应cmets
【问题讨论】: