r - rvest 不会超过一定数额
问题描述
我正在尝试抓取此网站 url= https://www.kimovil.com/en/compare-smartphones/f_min_dm+unveileddate.3,i_b+slug.samsung
我正在使用 rvest 来抓取这个网站。这是我正在使用的代码。
site <- 'https://www.kimovil.com/en/compare-smartphones/f_min_dm+unveileddate.3,i_b+slug.samsung'
website <- read_html(site)
device_label_html <- html_nodes(website,'div.device-name')
device_label <- html_text(device_label_html)
head(device_label,n=60)
运行此代码后,它最多需要 40 个结果(电话),尽管它应该是 51 个结果(电话)。有人可以帮我解决这个问题。谢谢你。
解决方案
该网站是内部分页的。可能有一种更优雅的方式来做到这一点。如果它超过 2 页,我肯定会找一个,但这有效:
library(rvest)
site <- 'https://www.kimovil.com/en/compare-smartphones/f_min_dm+unveileddate.3,i_b+slug.samsung'
website <- read_html(site)
device_label_html <- html_nodes(website,'div.device-name')
device_label <- html_text(device_label_html)
site2 <- 'https://www.kimovil.com/en/compare-smartphones/f_min_dm+unveileddate.3,i_b+slug.samsung,page.2'
website2 <- read_html(site2)
device_label_html2 <- html_nodes(website2,'div.device-name')
device_label2 <- html_text(device_label_html2)
head(c(device_label, device_label2),n=60)
推荐阅读
- visual-studio - 使用“Visual Studio 2019 -> Build”成功构建项目,但使用“MSBuild”失败
- c# - C#内部布尔?变量的名称; 这是什么意思
- arm - 在 QEMU 中运行带有 FPU 的 Arm cortex M4
- php - 升级到 Laravel 7 后日期未转换
- c# - 创建对象的单元测试方法,麻烦断言
- javascript - 在 JavaScript 中评估字符串时的错误
- firebase - 在 null 上调用了方法“[]”。接收方:null 尝试调用:[]("color")
- php - 重定向时会话未写入
- java - Spring boot和mySQL获取一对多关系的请求
- mysql - 如果是客户的第一个订单,计算订单日期