0

I am trying to scrape a table that I believe is using Java script. I want to get the data for indices (i.e., TSX). I would like to get the "Previous day data" for all indices. I am scraping the data using Rselenium but it is unable to locate the element.

Following is my code for scraping previous day data for index called TSX:

library(RSelenium)
driver<- rsDriver(browser = "firefox")
remDr <- driver[["client"]]

remDr$navigate("http://bmgfunds.com/interactive-charts/")

elem <- remDr$findElement(using="xpath", value="//*[@id='indices-quotes']/table/tbody/tr[1]/td[2]")

In order to get the Xpath, I inspected the element and copied the Xpath by right clicking in the pan. I also tried using rvest.

library(rvest)

st_table <- read_html("http://bmgfunds.com/interactive-charts/")
table<-html_nodes(st_table, "tbody tr")

Unfortunately, I get zero element {xml_nodeset (0)}

Any suggestion or help will be appreciated.

Dave2e
  • 22,192
  • 18
  • 42
  • 50
Cricketer
  • 399
  • 1
  • 3
  • 20

1 Answers1

1

The table is within an iframe whose source is http://integration.nfusionsolutions.biz/client/bullionmanagementgroup/module/quotechartfull, so you can grab the table from there:

st_table <- read_html("http://integration.nfusionsolutions.biz/client/bullionmanagementgroup/module/quotechartfull") 
(table <- html_table(st_table)[[3]])

This code grabs all the tables from the previous url with html_table and selects the table that you want (which is the third element of the list).

Pol Ferrando
  • 663
  • 4
  • 11