雅虎财务下载装置停止工作

时间:2017-05-18 13:09:42

标签: java connection yahoo

我有一个JAVA程序,我去年一直在使用它来下载来自雅虎财经的数据。几天前它停止了工作,雅虎开始拒绝连接。

java.net.ConnectException: Connection refused: connect

还有其他人经历过这个吗?

import java.net.URL;
import java.net.URLConnection;
import java.util.Calendar;
import java.util.Scanner;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;

public class C_GetStocksFromYahoo {
    public Scanner input;

    public void GetStocks(String symbol, GregorianCalendar start, GregorianCalendar end) {  
        String url = "http://real-chart.finance.yahoo.com/table.csv?s="
            + symbol
            + "&a=" + start.get(Calendar.MONTH)
            + "&b=" + start.get(Calendar.DAY_OF_MONTH)
            + "&c=" + start.get(Calendar.YEAR)
            + "&d=" + end.get(Calendar.MONTH)
            + "&e=" +end.get(Calendar.DAY_OF_MONTH)
            + "&f=" + end.get(Calendar.YEAR)
            + "&g=d&ignore=.csv"; //g=d means daily stock quotes

        try {
            URL yhoofin=new URL(url);//Create New URL data
            URLConnection data=yhoofin.openConnection();//Open a connection
            input = new Scanner(data.getInputStream());//get data from input stream 
            //System.out.println("This is the scanner " + input);
            //System.out.println("This is the first line " + this.nextline());
            //System.out.println("This is the first line " + this.nextline());
        } catch (Exception e) {
            System.out.println("This is the symbol i failed on " + symbol);
            System.err.println(e);
        }
    }

    //scanner value
    public Scanner getScan() {
        return input;
    }

    //determine if file has next entry
    public boolean hasnext() {
        return input.hasNext();
    }

    //contains next line
    public String nextline() {
        return input.nextLine();
    }

    public void closeConnection() {
        input.close();
    }
}

1 个答案:

答案 0 :(得分:0)

不幸的是,雅虎停止使用其历史数据API,因此您的网址http://real-chart.finance.yahoo.com/table.csv?将不再为您提供任何数据。

On https://forums.yahoo.net/t5/Yahoo-Finance-help/Is-Yahoo-Finance-API-broken/td-p/250503/page/3 Nixon(官方'Hoo Staff)说:

  

大家好 - 此功能已由财务团队停止,他们不会重新引入该功能。

取自:Yahoo Finance URL not working