I'm trying to scrape in any Amazon search to get products and their prices so I'm working with rvest library in R to do that.
For example, for this search:
I want to extract all product names and their prices. I tried the follow:
library(rvest)
link='https://www.amazon.com.mx/s?k=gtx+1650+super&__mk_es_MX=%C3%85M%C3%85%C5%BD%C3%95%C3%91&ref=nb_sb_noss_2'
simple=read_html(link)
simple %>% html_nodes("[class='a-size-base-plus a-color-base a-text-normal']") %>% html_text()
Using Chrome, class 'a-size-base-plus a-color-base a-text-normal' is where product name it's stored.
That code works fine and I get all the products names. So, I was trying to get theirs prices with this:
simple %>% html_nodes("[class='a-offscreen']") %>% html_text()
Using Chrome, class 'a-offscreen' is where price it's stored.
That code returns me every price in the search but if you have seen the search, not all products have price. So, that code returns me products with price and I can't match products with their prices.
Is there a way to make it possible? maybe it can be possible filter only those products that have class 'a-offset' and get their prices?
Thanks.