Extract data using RVEST

I'm trying to extract some data to create an analysis of the prices of my favorite trading game card, this is my code, but in the price, the info was extracted as NA instead the value.

Can anyone help me with this?
this is my code.

library(xml2)
library(rvest)
url<-"https://starcitygames.com/shop/singles/english/throne-of-eldraine/"
pagina_web<-read_html(url)

selectorExpansion<-"body > div.body.category-grid-view > div.container > div > h1"
Expansion_nodo<-html_node(pagina_web,selectorExpansion)
Expansion<-html_text(Expansion_nodo)
Expansion

selectorNombre1<-"#product-listing-container > section > article > table > tbody > tr:nth-child(1) > td.td-listItem.--Name.fixed > div > h4 > a"
Nombre1_nodo<-html_node(pagina_web,selectorNombre1)
Nombre1<-html_text(Nombre1_nodo)
Nombre1

selectorIdioma1<-"#product-listing-container > section > article > table > tbody > tr:nth-child(1) > td.td-listItem.--Name.fixed > div > p"
Idioma1_nodo<-html_node(pagina_web,selectorIdioma1)
Idioma<-html_text(Idioma1_nodo)
Idioma


selectorPrecio1<-"#product-listing-container > section > article > table > tbody > tr:nth-child(2) > td.td-listItem.--Quantity.fixed.qty > p"
Precio1_nodo<-html_node(pagina_web,selectorPrecio1)
Precio1<-html_text(Precio1_nodo)
Precio1

Welcome to RStudio Community @Otho72 ,

It seems the website loads the price values dynamically after the website is opened. Unfortunately, rvest pulls the source code before the site is completely loaded. If you check the all retrieved classes (see below), you would not see the product-price sort-name class which indicates the price value in the source.

library(xml2)
library(rvest)
library(dplyr)

url<-"https://starcitygames.com/shop/singles/english/throne-of-eldraine/"
pagina_web<-read_html(url)

pagina_web %>% 
  html_nodes("*") %>% 
  html_attr("class") %>% 
  unique() # Total 156 classes

So in this case you may try scripted web browser packages such as RSelenium. It basically mimics the an ordinary browser but you can control every action (even the mouse clicks) with R commands.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.