Yahoo! Finance CSV file will not return Dow Jones (^DJI)

后端 未结 8 2012
Happy的楠姐
Happy的楠姐 2020-11-30 00:37

I am trying to retrieve market data from Yahoo! finance and the script has worked fine for years, but recently, it stopped showing The Dow Jones data. Here is the URL:

8条回答
  •  天涯浪人
    2020-11-30 01:11

    The following link: http://finance.yahoo.com/q/hp?s=^DJI will give you some of the information that you are interested in (like Open, DaysHigh, and DaysLow).

    Furthermore, the following non-functioning code:

    wget -qO ^DJI.csv "http://ichart.finance.yahoo.com/table.csv?s=^DJI"
    

    can be replaced with the following hack:

    (echo "Date,Open,High,Low,Close,Volume,Adj Close"
    for y in {0..7603..66}; do # increase 7603 if necessary
      wget -qO- "http://finance.yahoo.com/q/hp?s=^DJI&y=$y" |
        sed 's/<\/\(td\|a\)>/\n/g' |
        grep yfnc_tabledata1 |
        sed -e 's/<.*>//g' -e 's/\([0-9]\),\([0-9]\)/\1\2/g' |
        grep -v ^$ |
        awk 'BEGIN {m["Jan"]=1; m["Feb"]=2; m["Mar"]=3;
        m["Apr"]=4; m["May"]=5; m["Jun"]=6;
        m["Jul"]=7; m["Aug"]=8; m["Sep"]=9;
        m["Oct"]=10; m["Nov"]=11; m["Dec"]=12}
        NR%7==1 {printf "%d-%02d-%02d,",$3,m[$1],$2}
        NR%7>1 {printf "%s,",$0} NR%7==0'
    done) > ^DJI.csv
    

    which will generate a table with daily historical data for the ^DJI starting from January 29, 1985.

提交回复
热议问题