【发布时间】:2021-06-18 05:19:48
【问题描述】:
我一直在通过 lappy 在具有多个页面的网页上使用 rvest 进行抓取,但是我遇到了一个错误: UseMethod("xml_find_all") 中的错误: 'xml_find_all' 没有适用的方法应用于“list”类的对象
不完全确定如何解决它:
url <-'https://www.bunnings.com.au/products/bathroom-plumbing/plumbing/pipe-fittings/push-fit-pipe-fittings?L0=products&L1=bathroom-plumbing&L2=plumbing&L3=pipe-fittings&L4=push-fit-pipe-fittings&pageSize=36&page=1'
get_last_page <- function(html){
pages_data <- html %>%
html_nodes('.MuiPaginationItem-sizeLarge') %>%
html_text()
pages_data[(length(pages_data)-1)] %>%
unname() %>%
as.numeric()
}
first_page <- read_html(url)
(latest_page_number <- get_last_page(first_page))
list_of_pages <- str_c(url, '?page=', 1:latest_page_number)
bun <- list_of_pages %>%
lapply(read_html)
data.frame(
paint = bun %>% html_nodes(".product-title") %>% html_text(),
price = bun %>% html_nodes(".price-medium-size p") %>% html_text()
)
【问题讨论】: