首页 > 解决方案 > Reddit 使用 rvest 时只返回 25 个帖子而不是 100 个

问题描述

我以本指南为例来了解帖子发布到 Reddit 的时间。

它说要使用 SelectorGadget 工具来绕过学习其他语言,所以这就是我所做的。

虽然 old.reddit.com 上的页面显示了 100 个帖子(因此应该记录 100 个不同的时间),但实际上从我的代码中只提取了 25 个不同的时间值。这是我的代码的样子:

library(rvest)

url <- 'https://old.reddit.com/'

rawdata <- read_html(url)

rawtime <- html_nodes(rawdata, '.live-timestamp')
  #".live-timestamp" was obtained using the Chrome extension "SelectorGadget" 

finalresult <- bind_rows(lapply(xml_attrs(rawtime), function(x) data.frame(as.list(x), stringsAsFactors=FALSE)))

标签: rrvestreddit

解决方案


您需要登录或使用?limit=100参数才能在列表中获取 100 项。

有关更多信息,请参阅API 文档

limit: the maximum number of items desired (default: 25, maximum: 100)


推荐阅读