1

For some reason both of these work:

var fetchString="http://ichart.finance.yahoo.com/table.csv?s=SPY&a=1&b=4&c=2011&d=1e=4&f=2013&g=d"
var response = UrlFetchApp.fetch(fetchString)


var fetchString="http://ichart.finance.yahoo.com/table.csv?s=IBM&a=1&b=4&c=2011&d=1e=4&f=2013&g=d"
var response = UrlFetchApp.fetch(fetchString)

but this doesn't work:

var fetchString="http://ichart.finance.yahoo.com/table.csv?s=^GSPC&a=1&b=4&c=2011&d=1e=4&f=2013&g=d"
var response = UrlFetchApp.fetch(fetchString)

this doesn't work also:

var fetchString="http://ichart.finance.yahoo.com/table.csv?s=^HSI&a=1&b=4&c=2011&d=1e=4&f=2013&g=d"
var response = UrlFetchApp.fetch(fetchString)

It seems the "^" is throwing it off? But if you paste that url into any browser the data comes over. Anybody know what's going here?

Could this be a bug?

4

1 に答える 1

2

From RFC 1738 specification:

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.

If you encode the special characters other than listed above & reserved characters, it will work. Browsers do this automatically.

Here is a working code.

var fetchString="http://ichart.finance.yahoo.com/table.csv?s="+encodeURIComponent('^')+"HSI&a=1&b=4&c=2011&d=1e=4&f=2013&g=d";
  var response = UrlFetchApp.fetch(fetchString);
于 2013-02-04T04:25:29.170 に答える