Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

run java script in R

$
0
0

I'm trying to use R to run javascript from a webpage. and create internal variables in R. I could do this with web drivers like selenium but I want to this with javascript engine v8 from inside R instead of from a browser instance. However, I cannot create a window object in the V8 engine. Here is my code to read and evaluate javascript in a page:

library('rvest')
library("V8")
library("dplyr")
url <- 'https://google.com'
webpage        <- read_html(url)
script         <- html_nodes(webpage,'script') %>% html_text %>% paste(collapse = "\r\n")
ct <- v8()
ct$eval(src = script)

in javascript code, they referred to internal dom objects like document, body and etc. which I don't care about them, but I cannot run the rest of the code; I'm getting error like ReferenceError: the document is not defined. is there any way to create a dummy window object in V8 engine independent from the browser? or even better determine to skip any line than you cannot execute?


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>