如何在给定的时间段内删除所有subreddit帖子

如何在给定的时间段内删除所有subreddit帖子,r,web-scraping,text-mining,reddit,R,Web Scraping,Text Mining,Reddit,我有一个功能,可以在2014-11-01和2015-10-31之间删除比特币子Reddit中的所有帖子 然而,我只能提取大约990篇只追溯到10月25日的帖子。我不明白发生了什么事。参考后,我在每次提取之间加入了15秒的Sys.sleep,但没有效果 此外,我还尝试了从另一个subreddit(fitness)中删除,但它也返回了大约900条帖子 require(jsonlite) require(dplyr) getAllPosts <- function() { url &l

我有一个功能,可以在2014-11-01和2015-10-31之间删除比特币子Reddit中的所有帖子

然而,我只能提取大约990篇只追溯到10月25日的帖子。我不明白发生了什么事。参考后,我在每次提取之间加入了15秒的Sys.sleep,但没有效果

此外,我还尝试了从另一个subreddit(fitness)中删除,但它也返回了大约900条帖子

require(jsonlite)
require(dplyr)

getAllPosts <- function() {
    url <- "https://www.reddit.com/r/bitcoin/search.json?q=timestamp%3A1414800000..1446335999&sort=new&restrict_sr=on&rank=title&syntax=cloudsearch&limit=100"
    extract <- fromJSON(url)
    posts <- extract$data$children$data %>% dplyr::select(name, author,   num_comments, created_utc,
                                             title, selftext)  
    after <- posts[nrow(posts),1]
    url.next <- paste0("https://www.reddit.com/r/bitcoin/search.json?q=timestamp%3A1414800000..1446335999&sort=new&restrict_sr=on&rank=title&syntax=cloudsearch&after=",after,"&limit=100")
    extract.next <- fromJSON(url.next)
    posts.next <- extract.next$data$children$data

    # execute while loop as long as there are any rows in the data frame
    while (!is.null(nrow(posts.next))) {
        posts.next <- posts.next %>% dplyr::select(name, author, num_comments, created_utc, 
                                    title, selftext)
        posts <- rbind(posts, posts.next)
        after <- posts[nrow(posts),1]
        url.next <- paste0("https://www.reddit.com/r/bitcoin/search.json?q=timestamp%3A1414800000..1446335999&sort=new&restrict_sr=on&rank=title&syntax=cloudsearch&after=",after,"&limit=100")
        Sys.sleep(15)
        extract <- fromJSON(url.next)
        posts.next <- extract$data$children$data
    }
    posts$created_utc <- as.POSIXct(posts$created_utc, origin="1970-01-01")
    return(posts)
}

posts <- getAllPosts()
require(jsonlite)
需要(dplyr)
getAllPosts是的,所有reddit列表(帖子、评论等)的上限为1000项;出于性能原因,它们本质上只是缓存列表,而不是查询


要解决这个问题,您需要进行一些巧妙的搜索。

如果我编写一个函数,其中每个迭代捕获4天的数据,这会绕过Reddit的限制吗?换句话说,我是否能够运行此功能并获得全年的帖子?取决于您是否认为在这4天内可能有1000篇帖子。按new排序和使用您可以访问的最后一篇文章的时间戳可能会更容易。