Domanda

I'm trying to get stock data from yahoo using the method found here http://www.gummy-stuff.org/Yahoo-data.htm and when using UrlFetchApp.fetch on any stock URLs, it fails most of the time. Note that the same url works perfectly if I navigate to it through my browser.

Code,

var resp = UrlFetchApp.fetch("http://finance.yahoo.com/d/quotes.csv?s=" + securityName + "&f=sl1d1t1c1ohgv&e=.csv");

Where securityName is a stock symbol like AAPL or MSFT. Usually the error is address unavailable. It always works when I navigate to it through my browser.

È stato utile?

Soluzione

The error is associated with yahoo site. I made the test through javascript and had the same problem. If you want to test access download.finance.yahoo.com and them open chrome console via F12 and put the code bellow:

function test() {
    for(var x = 0; x < 100; x++) {
        var req = new XMLHttpRequest();
        req.open("GET", "http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=sl1d1t1c1ohgv&e=.csv", false);
        req.send();
        if(req.status != 200) {
            console.log("ERROR"); return;
        }else {
            console.log("OK");
        }
    }

}

test();

Check in my example that it worked 8 times (8 OK's) but in the 9th try it failed. enter image description here

Altri suggerimenti

I am using the same script for months and the error has started appearing only recently, seems like Yahoo! screwed something up.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top