我想使用https://irelandsgreatwardead.ie/the-archive/从rvest中抓取一个表格(包含关于31,385名士兵的信息)。
library(rvest)
library(dplyr)
page <- read_html(x = "https://irelandsgreatwardead.ie/the-archive/")
table <- page %>%
html_nodes("table") %>%
html_table(fill = TRUE) %>%
as.data.frame()这是可行的,但只适用于前10名士兵。在源代码中,我只能看到前10名士兵的信息。任何帮助如何获得与其他士兵的排将是非常感谢的!
谢谢,祝您今天愉快!
发布于 2021-11-21 12:36:48
library(RSelenium)
driver = rsDriver(browser = c("firefox"))
remDr <- driver[["client"]]
url <- 'https://irelandsgreatwardead.ie/the-archive/'
remDr$navigate(url)
# Locate the next page link
webElem <- remDr$findElement(using = "css", value = "a[data-dt-idx='3'")
# Click that link
webElem$clickElement()
# Get that table
remDr$getPageSource()[[1]] %>%
read_html() %>%
html_table()您的for循环需要从值3开始(这是第二个页面!)。在第二页,它变成4,等等,但它永远不会超过5。因为它是‘设计’的方式,所以你会循环3:5,然后在5,保持在每次5。
https://stackoverflow.com/questions/70048987
复制相似问题