"rvest" 未使用 html_nodes() 获取产品详细信息

"rvest" not fetching the product details using html_nodes()

我正在使用 rvest 抓取 亚马逊产品搜索 results 上的产品详细信息(名称、价格和可用性)。我能够使用 read_html() 获取网页,但无法获取产品的详细信息(名称、价格和可用性)。该页面有 <span> 标记,class 为 class = "a-size-medium a-color-base a-text-normal"。我已经使用了 html_nodes("span.a-size-medium a-color-base a-text-normal"),但得到了 NA

这是可重现的代码:

library(rvest)
library(xml2)

url <- "https://www.amazon.in/s?k=Smartphone&rh=n%3A1389401031&ref=nb_sb_noss"

page <- read_html(url)

data <- page%>%
  html_node("span.a-size-medium a-color-base a-text-normal") %>%
  html_text()

print(data)

您只需稍微更改 css 选择器。我能够获得名称和价格,可用性有点棘手:/

library(rvest)
library(xml2)

url <- "https://www.amazon.in/s?k=Smartphone&rh=n%3A1389401031&ref=nb_sb_noss"

page <- read_html(url)

name <- page %>% html_nodes(".a-size-medium.a-color-base.a-text-normal") %>% html_text()

price <- page %>% html_nodes(".a-price-whole") %>% html_text()