library(rvest)
library(stringr)
options(digits = 5, scipen = 100) # Setting max to five significant digits
rm(list = ls()) # Clears the environment (R objects)
graphics.off() # Clears Graphics/Plots
cat("\014") # Clears the console
#################################################################################################################################################################################################################################################
MSid <- c('F0GBR06T61', 'F0GBR06T6F', 'F0GBR06T6D', 'F0GBR04EAN', 'F0GBR05ZUY', # 5
'F000000FH0', 'F0GBR04UGX', 'F0GBR04GNL', 'F0GBR04E6R', 'F00000VIK1', # 10
'F0GBR04SKK', 'F0GBR05XJ0', 'F0GBR04T1N', 'F0GBR057ZA', 'F00000N86D', # 15
'F0GBR05L20', 'F0GBR064Q5', 'F0000001V3', 'F0000001V0', 'F0000001V1', # 20
'F0000001V2', 'F00000PCHJ', 'F0GBR061VJ', 'F000000GMD', 'F000002FBY', # 25
'F0GBR04N92', 'F00000UPOP', 'F0GBR04RBZ', 'F000001ZHN', 'F00000WTML', # 30
'F000010L3X', 'F00000XE8F', 'F0GBR06E0A', 'F0GBR06IIX', 'F0000026XE', # 35
'F000000JV6', 'F0GBR04K7L', 'F0GBR04JGP', 'F00000MRIA', 'F0GBR06FVK', # 40
'F00000VYLS', 'F00000VYLT', 'F00000VYLU', 'F0000002SD', 'F000001WZS', # 45
'F00000OZ46', 'F00000OZGB', 'F0000000LE', 'F00000YJ6S', 'F00000UDC4', # 50
'F00000YXG6', 'F0GBR04AIK', 'F0GBR04SRH', 'F0GBR04AIU', 'F000011TN0', # 55
'F0GBR04SKF', 'F0GBR04G0F', 'F0GBR061V3', 'F00000T1HQ', 'F0GBR05A2X', # 60
'F0GBR06TSA', 'F00000PA9N', 'F00000NGKR', 'F00000T1I9', 'FOGBR05KNY', # 65
'F00000MIC6', 'F00000MO70', 'F0GBR04LWJ', 'FOGBR05K0E', 'F00000MO76', # 70
'F00000MIC3', 'F00000MIC8', 'F00000MIC1', 'F0GBR04D2G', 'F00000T4KE', # 75
'F00000Q8QC', 'F00000ZY64', 'F0GBR04V75', 'F0GBR06T5P', 'F00000J7E6', # 80
'F00000NRZS', 'F00000NGSG', 'F000000RLR', 'FOGBR05KLP', 'F0GBR04KNO', # 85
'F00000ND3V', 'F00000ND3U', 'F00000ND3T', 'F0GBR04KNM', 'F000000275', # 90
'F000000F87', 'F00000T1I8', 'F0GBR04EP3', 'F0GBR04D28', 'F00000Q4A8', # 95
'F0000004J1', 'F000000AVO', 'F0GBR06W8V', '0P0000GEK1', 'F000011S12', # 100
'F0000104Y4', 'F0000101QX', 'F0000101QW', 'F0000101QY', 'F0GBR04VDP', # 105
'F000002EX0', 'F0GBR04LVV', 'F000003YGQ', 'F00000YSYB', 'F00000LNTQ', # 110
'F00000WDSM', 'F0GBR04LVP', 'F00000UH71', 'F00000IRBH', 'F0000001NP', # 115
'F0GBR06T9O', 'F00000J5HW', 'F0GBR056YC', 'F000002HFH', 'F00000NY97', # 120
'F00000T4KE', 'F0GBR04VQR', 'F00000VDUR', 'F000003W9G', 'F00000OZZ4', # 125
'F00000MEJL', 'F0GBR04AFQ', 'F0GBR0580G', 'F00000TH42', 'F0GBR04EV4', # 130
'F00000259C')
#################################################################################################################################################################################################################################################
## AB_FCP ##
AB_FCP <-
"http://www.morningstar.es/es/funds/snapshot/snapshot.aspx?id=F0000020MG"
AB_FCP_html <- read_html(AB_FCP)
AB_FCP_name <- AB_FCP_html %>%
html_node("h1") %>%
html_text()
AB_FCP_ISIN <- AB_FCP_html %>%
html_node("#overviewQuickstatsDiv tr:nth-child(5) .text") %>%
html_text()
AB_FCP <- cbind("F0000020MG", AB_FCP_ISIN, AB_FCP_name)
AB_FCP <- chartr(".", ",", AB_FCP)
Fundos <- AB_FCP
## Fund ##
for (i in MSid) {
tryCatch({
Fund <-
paste0("http://www.morningstar.es/es/funds/snapshot/snapshot.aspx?id=",i)
Fund_html <- read_html(Fund)
Fund_name <- Fund_html %>%
html_node("h1") %>%
html_text()
Fund_ISIN <- Fund_html %>%
html_node("#overviewQuickstatsDiv tr:nth-child(5) .text") %>%
html_text()
Fund <- cbind(i, Fund_ISIN, Fund_name)
Fundos <- rbind(Fundos, Fund)
}, error=function(e){cat("Ooops, parece que houve um problema com o fundo", i,"\n")})
}
Fundos <- sub("%", "", Fundos)
colnames(Fundos) <- paste(c("MSid", "ISIN", "Nome"))
# write.table(Fundos, "Fundos.csv", row.names = F, col.names = T, sep = ";")
write.xlsx(Fundos, "Fundos2.xlsx", row.names = F)