Date : Jan-2021
Parse an html table into a data frame
install.packages('rvest')
library('rvest')
#dow jones components
url='https://www.dividendmax.com/market-index-constituents/dow-jones-30'
xpath='/html/body/div[2]/div[2]/div/div/div/div[2]/div/table'
wpage <- read_html(url)
wdf=wpage %>% html_nodes(xpath=xpath) %>% html_table()
head(wdf[[1]],n=5)
#yahoo hsi components
url='https://finance.yahoo.com/quote/%5EHSI/components/?guccounter=1&guce_referrer=aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS8&guce_referrer_sig=AQAAACp9HiHyrAzCcC9exwJ7K4thAXihsJhraS6VJR4yiJxlAbTjwCVmeBtUk2IS0IAWEqqSPVw0HOr5r87is6PhzeuAvYrBYjdhbU8ThKnvNUfDJTATsbM9-eiA_2GQlidLKqug9whSuIp9vdfgxbsi0kCami6RHLJQsqDpaevZjq62'
xpath='/html/body/div[1]/div/div/div[1]/div/div[3]/div[1]/div/div[1]/div/div/section/section/div/table'
wpage <- read_html(url)
wdf=wpage %>% html_nodes(xpath=xpath) %>% html_table()
head(wdf[[1]],n=5)