0

I am just messing around with the yahoo finance API and Commons CSV. I am having trouble outputting the value for stock symbol AAPL. For some reason I keep returning HTML. When I double check the website, it does in fact return a CSV file that works.

Please help! I need to return the Symbol value (for testing right now)

                 URL yahooData = new URL("http://finance.yahoo.com/d/quotes.csv?s=AAPL&f=svogh");

                 Reader yahooReader = new InputStreamReader(new BOMInputStream(yahooData.openStream()), "UTF-8");
                 CSVParser yahooParser = new CSVParser(yahooReader,
                 CSVFormat.EXCEL.withHeader("Symbol", "Volume", "Open", "Low", "High"));

                    for (final CSVRecord record : yahooParser) {
                        System.out.println(record.get("Symbol"));
                    }

As of right now this is what the CSV file contains:

 "AAPL",25473923,111.64,111.33,112.39
j1nrg
  • 69
  • 7
  • Where is your purported HTML output? – Tim Biegeleisen Apr 15 '16 at 01:44
  • 2
    Look at the HTML you get. It says `Description: The document you requested has moved to a new location. The new location is "http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=svogh". `. Your web browser is clever enough to follow that redirect. Your Java code is not. – Thilo Apr 15 '16 at 01:45
  • Wow, thank you. that fixes it :) I didn't think to look at the HTML. – j1nrg Apr 15 '16 at 01:48

0 Answers0