0

I am trying to extract a code (here: 3121040070932) from this webpage that is using what it looks like Javascript:

<body class=" language-fr">

   <script data-fstrz-fragment-selector="script:contains(var tc_vars)" data-fstrz-fragment-id="fstrz-scss-12" type="text/javascript">

...

      tc_vars['productDeliveryTime'] = undefined;
      tc_vars['productEAN'] = '3121040070932';
      tc_vars['productIsPriceReduced'] = 'true';
   </script>

I am using R and I have tried getting the source page using download.file() to extract the source code downloaded as text and then apply regex. But the downloaded file does not seem to contain the Javascript part.

I have read about the v8 package for JavaScript here and tried to apply the example as below but I can't extract anything:

library(rvest)
library(V8)
link <- 'https://www.conforama.fr/petit-electromenager/beaute-et-bien-etre/lisseur-fer-brosse/brosse-soufflante-calor-cf6220c0-express-air-brush/p/687739'
EANcode<- read_html(link) %>% html_nodes('body') %>% html_nodes('script') %>% html_text()
ct <- v8()
read_html(ct$eval(gsub('document.write','',EANcode))) %>% 
 html_text()

Help much appreciated!

ML_Enthousiast
  • 709
  • 9
  • 26

0 Answers0