Nathan Campos
Nathan Campos

Reputation: 29507

Get Only One Part Of a CSV URL

If you take a look at Yahoo Finance, you may notice that you can retrieve information from their servers using a URL, that might lead to a CSV file. Let's use as example this URL: http://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=USDBRL=X, it will return this:

"USDBRL=X",1.6294,"3/31/2011","12:06pm"

But how I can use that URL to retrieve that information and store only the money value(1.6294) part using Javascript?

Upvotes: 1

Views: 215

Answers (1)

Adam Byrtek
Adam Byrtek

Reputation: 12202

The simplest solution is to split the string into an array using str.split(",") and take the second element. This is not completely bulletproof (it assumes there are no commas in the first column), but it might be robust enough for a simple script.

Upvotes: 2

Related Questions