Assign Variables to extracted tibble from RSelenium to create data frame

Viewed 11

i wanted to scrape a stats table from a website with RSelenium. Therefor I wanted to assign a variable to the extracted tibble from RSelenium. I am not sure how to get the outputed tibble from RSelenium to convert it to a data frame for example. When I assign a variable to the output line for the tibble for example : "elemn_stats <- remDr$getPageSource()[[1]] %>% read_html() %>% html_nodes(xpath = '//*[@id="6-400-tab-container"]/div[1]/div[2]') %>% html_table()" then i get an empty list for example "list()".

The code

library(RSelenium)
library(dplyr)
library(rvest)
library(tidyverse)

url <- "https://www.kki.is/motamal/leikir-og-urslit/motayfirlit/Leikur?`enter code 
here`league_id=undefined&season_id=121199&game_id=5686693#mbt:6-400$t&0=1"
  
 remDr <- remoteDriver(remoteServerAddr = "localhost",
 port = 4444L, # change port according to terminal 
 browserName = "firefox"
  )

 remDr$open()

 remDr$navigate(url)

  elemn_stats <- remDr$getPageSource()[[1]] %>% 
   read_html() %>% html_nodes(xpath = '//*[@id="6-400-tab-container"]/div[1]/div[2]') %>% 
   html_table()

If i do it without assigning the variable elemn_stats to the output (only remDr$getPageSource()[[1]] %>% .....) then it works and i get a tibble. How can i get access to the tibble.

Thanks for the help in advanced.

0 Answers
Related