PRAW 6:获取subreddit的所有提交

PRAW 6: Get all submission of a subreddit

我正在尝试使用 PRAW 迭代某个 subreddit 的提交,从最新的到最旧的。我以前是这样做的:

subreddit = reddit.subreddit('LandscapePhotography')
for submission in subreddit.submissions(None, time.time()):
    print("Submission Title: {}".format(submission.title))

但是,当我现在尝试这样做时,出现以下错误:

AttributeError: 'Subreddit' object has no attribute 'submissions'

通过查看文档,我似乎无法弄清楚如何执行此操作。我能做的最好的是:

for submission in subreddit.new(limit=None):
    print("Submission Title: {}".format(submission.title))

但是,这仅限于前 1000 个提交。

有没有办法对所有提交的内容执行此操作,而不仅仅是前 1000 个?

不幸的是,Reddit 从他们的 API 中删除了这个功能。

查看 PRAW changelog。 6.0.0 版本的变化之一是:

Removed

链接的 post 表示 Reddit 正在为所有用户禁用 Cloudsearch:

Starting March 15, 2018 we’ll begin to gradually move API users over to the new search system. By end of March we expect to have moved everyone off and finally turn down the old system.

PRAW 的 Subreddit.sumbissions() 使用 Cloudsearch 在给定时间戳之间搜索 posts。由于 Cloudsearch 已被删除并且替代它的搜索不支持时间戳搜索,不再可能使用 PRAW 或任何其他 Reddit API 客户端执行基于时间戳的搜索.这包括尝试从 subreddit 获取所有 post。

有关详细信息,请参阅 this thread from /r/redditdev posted by the maintainer of PRAW


备选方案

由于 Reddit 将所有列表限制为 ~1000 个条目,因此目前不可能使用其 API 在 subreddit 中获取所有 post。但是,存在 API 的第三方数据集,例如 pushshift.io. As /u/kungming2 said on Reddit:

You can use Pushshift.io to still return data from defined time periods by using their API:

https://api.pushshift.io/reddit/submission/search/?after=1334426439&before=1339696839&sort_type=score&sort=desc&subreddit=translator

This, for example, allows you to parse submissions to r/translator between 2012-04-14 and 2012-06-2014.

您可以使用迭代循环从 pushshift.io 中检索所有数据。只需将开始日期设置为当前纪元日期,并获取 1000 个项目,然后将列表中最后一项的 created_utc 作为 before 参数,以获取接下来的 1000 个项目并继续执行直到停止返回。

下面是有用的 link 进一步信息: https://www.reddit.com/r/pushshift/comments/b7onr6/max_number_of_results_returned_per_query/enter link description here

Pushshift 不适用于私人 subreddits。在这种情况下,您可以从现在开始一次创建 1000 个提交的数据库(不追溯)。

如果您只需要尽可能多的提交,您可以尝试使用不同的排序方法 top、hot、new 并将它们结合起来。