股票报价与JavaScript [英] stock quotes with javascript

查看:114
本文介绍了股票报价与JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何使用javascript获取直播 - 或延迟20分钟 - 股票报价?
我在 http:// code中查看了google api。 google.com/apis/finance/docs/finance-gadgets.html
但很难找到一个有效的例子。

Does anyone know a way to get live - or 20 minutes delayed - stock quotes using javascript? I looked at the google api at http://code.google.com/apis/finance/docs/finance-gadgets.html but it was very hard to get a working example.

有没有人得到它来获取任何股票的报价,或找到更好的方法?

has anyone got it to work to get quote for any stock, or found a better way ?

谢谢。

推荐答案

花了一段时间,但这里是使用Yahoo!的YQL和jQuery的代码:

It took awhile but here is working code that uses Yahoo!'s YQL and jQuery:

<script type="text/javascript" src="jquery-1.5.1.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
            var symbol='goog';
            var callback = function(data) {
                    var price=data.query.results.span[0].content;
                    alert('Stock Price: ' + price);
                };

            var url = 'http://query.yahooapis.com/v1/public/yql';
            // this is the lovely YQL query (html encoded) which lets us get the stock price:
            // select * from html where url="http://finance.yahoo.com/q?s=goog" and xpath='//span[@id="yfs_l10_goog"]'
            var data = "q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3D" + symbol + "%22%20and%20xpath%3D'%2F%2Fspan%5B%40id%3D%22yfs_l10_" + symbol + "%22%5D'&format=json";
            $.getJSON(url, data, callback);
    });
</script>

这篇关于股票报价与JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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