Using Praw How Do You Get Comment Linked By A Url
I am trying to get the content linked to by a reddit URL, it could be a submission OR a comment, and I need to be able to get the corresponding object, does anyone know how to?
Solution 1:
If you are using PRAW (it seems you are from this answer) you can simply use the get_submission
function for either case.
importprawr= praw.Reddit('<USER AGENT>')
submission = r.get_submission('http://www.reddit.com/r/redditdev/comments/10msc8/how_to_calculate_more_comments_count_not_just/')
comment = r.get_submission('http://www.reddit.com/r/redditdev/comments/10msc8/how_to_calculate_more_comments_count_not_just/c6euu6b').comments[0]
To get the comment, we're using the permalink to the comment which returns the json data for the submission, along with the data for the comment and its children. However, in this case the comment tree will only have a single top-level comment thus comments[0]
is the desired comment.
Post a Comment for "Using Praw How Do You Get Comment Linked By A Url"