Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

I was using rvest for scrapping the details of the product (Names, Price, and Availability) on amazon's product search results. From that, I can fetch the webpage with read_html(), but I am not able to fetch the details of the product (Names, Price, and Availability). 

Here is the reproducible code:

library(rvest)

library(xml2)

url <- "https://www.amazon.in/s?k=Smartphone&rh=n:1389401031&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)

1 Answer

0 votes
by (108k points)

For that, you just need to change the CSS selector a little bit. In R programming, I was able to get the names and the prices but the availability was a little bit complex:

library(rvest)

library(xml2)

url <- "https://www.amazon.in/s?k=Smartphone&rh=n:1389401031&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()

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...