【问题标题】:Reddit only returning 25 posts instead of 100 when using rvestReddit 使用 rvest 时仅返回 25 个帖子而不是 100 个
【发布时间】:2019-06-24 15:21:52
【问题描述】:

我以this guide 为例来获取帖子发布到 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)))

【问题讨论】:

  • 当我打开你的 old.reddit 链接时,我看到了 25 个帖子,所以我认为当从 R 打开链接时会发生同样的事情。你应该看看多页抓取stackoverflow.com/a/36683564/7118188

标签: r rvest reddit


【解决方案1】:

或者,您可以使用 PRAW 从 Reddit 获取信息。这是针对您的问题的特殊解决方案,但可能有效。

https://praw.readthedocs.io/en/latest/

在 subreddit r/redditdev 中

【讨论】:

    【解决方案2】:

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

    更多信息请见the API documentation

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

    【讨论】:

      猜你喜欢
      • 2012-01-07
      • 2020-12-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多