praw6:获得subreddi的所有提交

2024-10-01 17:23:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用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'

看了这些文件,我似乎不知道该怎么做。我能做的就是:

^{pr2}$

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

有没有办法做到这一点,所有的提交,而不仅仅是前1000?在


Tags: innoneformatsubmissionfortimetitleprint
3条回答

不幸的是,Reddit从他们的API中删除了这个函数

查看PRAW changelog。版本6.0.0中的更改之一是:

Removed

链接帖子说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的^{}使用Cloudsearch搜索给定时间戳之间的帖子。由于Cloudsearch已被删除,而替换它的搜索不支持时间戳搜索,因此无法再使用PRAW或任何其他Reddit API客户端执行基于时间戳的搜索。这包括尝试从subreddit获取所有帖子。在

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


备选方案

由于Reddit将所有列表限制在大约1000个条目,所以目前不可能使用它们的API获取subreddit中的所有帖子。但是,存在具有api的第三方数据集,例如pushshift.io。作为/u/kungming2said 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键使用迭代循环。只需将start date设置为当前epoch日期,并获取1000个条目,然后将列表中最后一个条目的created_utc作为before参数来获取接下来的1000个条目,并继续下去,直到它停止返回为止。在

以下是获取更多信息的有用链接: 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并将它们组合起来。在

相关问题 更多 >

    热门问题