Web scraping in R with rvest and XML2 extract table

599 views Asked by At

I wish to extract the table with the ranks and returns from a sample URL https://www.valueresearchonline.com/funds/fundSelector/returns.asp?cat=10&exc=susp%2Cclose&rettab=st

So far tried rvest

#Reading the HTML code from the website
webpage <- read_html(urlString)

#Using CSS selectors to scrap the section
tables <- webpage %>% html_node("tr") %>% html_text()
tables <- html_node(".fundtool_cat") %>% html_text()

I need a dataframe/table with name of the scheme along with ranks and returns for all periods mentioned

1

There are 1 answers

0
Prem On BEST ANSWER
library(rvest)
urlString <- "https://www.valueresearchonline.com/funds/fundSelector/returns.asp?cat=10&exc=susp%2Cclose&rettab=st"
urlString %>%
  read_html() %>%
  html_nodes(xpath='//*[@id="fundCatData"]/table[1]') %>%
  html_table(fill=T)