# How to extract all the ticker symbols of an exchange with Quantmod in R?

I am using the Quantmod package in R for some data analysis. Now I can downbload price history of particular stocks or index with the following code:-

library(quantmod) # Loading quantmod library

getSymbols("^DJI", from = as.character(Sys.Date()-365*3))


I want to download all the ticker symbols that are composite of a particular Index such as DJI for example. What will be the best way to do that through R?

You need the components. You could use yahoo or cnn site, and read the table from that. Then get the tickers. Read all to an environment and work with the data.

library(XML)
urlt <- "http://money.cnn.com/data/dow30/"
doc.html = htmlTreeParse(urlt, useInternal = TRUE)
length(tables)
tables[[2]]