Search code examples
rweb-scrapingdata-extraction

How to extract tabular data from a website using R


I am trying to extract the data from the webpage https://www.geojit.com/other-market/world-indices and many others similar to this.

I need to get the tabular data of the website (INDEX,NAME,COUNTRY,CLOSE,PREV.CLOSE,NET CHANGE,CHANGE (%),LAST UPDATED DATE & TIME). would be great if you can share the R code for this or any help would be welcome.

library(rvest)
library(dplyr)   
google <- html("https://www.geojit.com/other-market/world-indices")    
google %>%    
html_nodes()

Solution

  • library(rvest)
    my_tbl <- read_html("https://www.geojit.com/other-market/world-indices") %>%    
      html_nodes(xpath = "//*[@id=\"aboutContent\"]/div[2]/table") %>%
      html_table(header = TRUE) %>%
      `[[`(1)