【问题标题】:Getting the body of a Reddit submission?获取 Reddit 提交的正文?
【发布时间】:2020-02-21 06:22:16
【问题描述】:

我正在尝试通过抓取 Reddit 来搜索一些数据。我想在 subreddit 中获取帖子的自文本,而不是标题/网址。我怎样才能做到这一点?这是我用来获取标题的代码,但是我怎样才能得到带有这个标题的帖子中的文字呢?

reddit = praw.Reddit(client_id=cid,
                     client_secret=secret, password=pass_word,
                     user_agent='mmm', username=user_name)

subreddit = reddit.subreddit('python')
subreddit_hot=subreddit.hot(limit=5)
for submission in subreddit_hot:
    if not submission.stickied:
        print(submission.title)

【问题讨论】:

    标签: reddit praw


    【解决方案1】:

    print(submission.title) 替换为print(submission.selftext)

    要查看Submission 对象的其他属性,请查看the PRAW docs,其中包含模型的通用属性表。 PRAW 的文档还包含 a guide for discovering attributes on any model

    【讨论】:

      猜你喜欢
      • 2014-11-07
      • 2020-11-23
      • 2020-05-23
      • 2020-08-13
      • 2017-01-21
      • 2012-07-03
      • 1970-01-01
      • 2021-07-24
      • 1970-01-01
      相关资源
      最近更新 更多