我无法使用 Rvest 刮掉价格,但是可以使用 RSelenium:
library(RSelenium)
# I use RSelenium in combination with docker.
remDr <- remoteDriver(
remoteServerAddr = "localhost",
port = 4445L,
browserName = "chrome"
)
remDr$open()
remDr$navigate("https://www.dicasanet.com.br/material-de-construcao")
page <- read_html(remDr$getPageSource()[[1]])
page %>% html_nodes("product-price") %>% html_text()
price <- remDr$findElements(using = "class","product-price")
price <- sapply(price,function(x){x$getElementText()[[1]]})
price
输出是:
price
[1] "" "" "" ""
[5] "" "" "R$ 40,50" "R$ 40,50"
[9] "R$ 194,90" "R$ 194,90" "R$ 171,00\nR$ 122,90" "R$ 171,00\nR$ 122,90"
[13] "R$ 393,00" "R$ 393,00" "R$ 357,50" "R$ 357,50"
[17] "R$ 433,20" "R$ 433,20" "R$ 120,60" "R$ 120,60"
[21] "R$ 89,50" "R$ 89,50" "R$ 56,20" "R$ 56,20"