【问题标题】:Reddit api return the content of a comment or a self.textReddit api 返回评论或 self.text 的内容
【发布时间】:2014-10-27 08:04:28
【问题描述】:

查看文档后,我仍然无法理解它是如何捆绑在一起的。我想要完成的事情很简单:给定一个 url,返回该 url 的文本内容。

例如:

import praw

r = praw.Reddit(user_agent='my_cool_app')


post  = "http://www.reddit.com/r/askscience/comments/10kp2h\
         /lots_of_people_dont_feel_identified_or_find/"
comment = "http://www.reddit.com/r/askscience/comments/10kp2h\
           /lots_of_people_dont_feel_identified_or_find/c6ec6hf"

可以使用正则表达式来确定哪个是评论,哪个是帖子,但如果有更好的方法,我会使用它。

所以我的问题是:确定 reddit url 的性质以及如何获取该 url 的内容的最佳方法是什么?

到目前为止我尝试了什么:

post=praw.objects.Submission.get_info(r, url).selftext 
#returns the self.text of a post regardless if that url is a permalink to a comment

comment_text = praw.objects.?????() # how to do this ?

提前致谢。

【问题讨论】:

    标签: reddit


    【解决方案1】:
    import praw
    r = praw.Reddit('<USERAGENT>')
    comment_url = ('http://www.reddit.com/r/askscience/comments/10kp2h'
                   '/lots_of_people_dont_feel_identified_or_find/c6ec6hf')
    comment = r.get_submission(comment_url).comments[0]
    print comment.body
    

    我的回复 herehere 应该会提供与您的问题相关的其他有用信息。

    【讨论】:

    • 谢谢,但我通过文档找到了自己的方式,但仍然感谢帮助我。有一个史诗般的一天。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    • 2022-08-22
    • 2020-06-30
    • 2018-02-15
    • 1970-01-01
    • 2020-10-17
    相关资源
    最近更新 更多