REQUIREMENTS

  1. CHROME BROWSERS to review the HTML.

  2. Any url site you wish to retrieve.

SCRIPTS BELOW

library(rvest)
## Loading required package: xml2
url4="https://en.wikipedia.org/wiki/List_of_secondary_schools_in_Singapore#Mainstream_Schools"


# MAIN information is XPATH. See below for explanation on how to retrieve it.

school <- url4 %>% read_html() %>% 
  html_nodes(xpath = '//*[@id="mw-content-text"]/div/table[1]') %>%
  html_table(fill=TRUE)

school <- school[[1]]

# display table
library(DT)
datatable(school)
# View(school) which is more like a dataset

EXPLANATION

I use GOOGLE CHROME to first open the above URL.

The main information is the XPATH and must start with an ‘and close with’. I will show how to get the XPATH.

Move your mouse to the URL table and right mouse click INSPECT.

Look for HTML TABLE CLASS on the RIGHT HAND SIDE and do a COPY OF XPATH

FINALLY - Copy the XPATH information your script. That’s all !