r - 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)))
解决方案
您需要登录或使用?limit=100
参数才能在列表中获取 100 项。
有关更多信息,请参阅API 文档:
limit: the maximum number of items desired (default: 25, maximum: 100)
推荐阅读
- ios - Xamarin Forms 软键盘的文化不正确
- python - 字符串中出现的非 ASCII 字符
- react-native - 在本机反应中同时获取单击和移动事件
- python - 如何验证 pip 的 --extra-index-url?
- javascript - 如何使用滑动检测构建触摸手势?
- excel - 如何将超链接复制到只有路径的单元格?
- chef-infra - 如何为 Seven_zip_archive 资源编写 chefspec 代码?
- sql - 在 BigQuery 中更新分区表和聚簇表
- jquery - 如何使用来自 jquery 加载的返回值和回调函数中的变量值相同的 jquery 加载?
- docker - 如何将 jupyter/all-spark-notebooks 容器与 docker 中的 hadoop 多节点集群连接起来