读取从网址下载的csv数据中的单个数据 [英] Read single data in csv data downloaded from url

查看:158
本文介绍了读取从网址下载的csv数据中的单个数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Yahoo! Finance获取数据,以获取与此网址进行货币兑换的价值,假设我在javascript中兑换USD到EUR的货币。

I'm trying to fetch the data from Yahoo! Finance to get value for currency exchange with this url assuming I'm getting currency exchange for USD to EUR in javascript

http://download.finance.yahoo.com/d/quotes.csv?s=USDEUR=X&f=l1

在csv中,我将只收到一个我需要的值。例如。 - '0.8994'

in the csv, I would receive just the one value I need. Eg. - '0.8994'

现在,在同一个javascript文件中,我想将此值传递给一个变量

Now, in same javascript file, I want this value to be pass into a variable

var USDEUR;

此时,我不知道如何从下载的csv传递值。有人能告诉我如何正确地这样做吗?

at this point, I'm not sure how to pass the value from the downloaded csv. Could someone enlighten me how to do this properly?

提前感谢

推荐答案

需要将这个文件解析为csv,它基本上是一个纯文本字符串?假设jquery:

It seems you don't actually need to parse this file as a csv, it's basically a plain text string? Assuming jquery:

var USDEUR;
$.ajax({
    type: "GET",
    url: "http://download.finance.yahoo.com/d/quotes.csv?s=USDEUR=X&f=l1",
    dataType: "text",
    success: function(data) {USDEUR = data}
 });

编辑:似乎网址有访问控制问题,您可能无法使用来自客户端的XHTTP请求。此数据是否意味着作为公共API访问?

It seems the url has access control issues, you may not be able to do this with a XHTTP request from the client. Is this data meant to be accessed as a public API?

这篇关于读取从网址下载的csv数据中的单个数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆