谷歌财经,如何获得JSON数据流? [英] Google Finance, how to get the JSON data streamed?
问题描述
我试图解释这个较早,但显然没有!
I tried to explain this earlier, but obviously failed!
所以,如果你有一个谷歌的财务图表开放,例如:
So, if you have a google finance graph open, for instance:
http://www.google.com/finance?q=INDEXNASDAQ:。 IXIC
我想以某种方式使用(HttpWebRequest的)对象在C#中,这样我可以抓住小数据,谷歌发送到页面来更新图表。
I would like to somehow use the (HttpWebRequest) object in C# so that I can grab the small data which google sends to the page to update the graph.
有一个朋友提到这是JSON?
A friend mentioned this was JSON?
我尝试使用下面的code的例子,但即使当我设置保持活动属性设置为真,它仍然wouldnt工作:
I was trying to use the following code example, but even when i set the keep alive property to 'true', it still wouldnt work:
的http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.keepalive.aspx#Y369
推荐答案
您还需要更改设置连接的例子的行
属性关闭
。注释掉这一行(以及保持设置为true保持活跃性):
You also need to change the example's line that sets the Connection
property to Close
. Comment out this line (along with keeping the keep-alive property set to true):
myHttpWebRequest2.Connection = "Close";
您做到这一点,你的榜样应该运行正常。
You do that and your example should run fine.
对于获取数据,并使用的HttpWebRequest
与它的工作,你可以做到这一点。返回的数据是不是JSON - 它看起来像连胜文和我猜测谷歌的javascript解析出来。 (我还没有检查,对谷歌财经的页面上的JavaScript,但是这是我的猜测。)
Regarding getting the data and using HttpWebRequest
to work with it, you can do that. The data returned isn't JSON - it looks like straight text and I'm guessing Google's javascript is parsing it out. (I haven't inspected the javascript on Google Finance's page, but that's my guess.)
使用招,从这个URL的响应:
Using Fiddler, the response from this URL:
<一个href="http://www.google.com/finance/getprices?q=.IXIC&x=INDEXNASDAQ&i=120&p=10m&f=d,c,v,o,h,l&df=cpct&auto=1&ts=1307994768643" rel="nofollow">http://www.google.com/finance/getprices?q=.IXIC&x=INDEXNASDAQ&i=120&p=10m&f=d,c,v,o,h,l&df=cpct&auto=1&ts=1307994768643
看起来是这样的:
EXCHANGE%3DINDEXNASDAQ
MARKET_OPEN_MINUTE=570
MARKET_CLOSE_MINUTE=960
INTERVAL=120
COLUMNS=DATE,CLOSE,HIGH,LOW,OPEN,VOLUME
DATA=
TIMEZONE_OFFSET=-240
a1307994120,2641.12,2641.12,2639.96,2640.01,0
1,2638.76,2642.14,2638.76,2641.13,0
2,2638.95,2640.54,2638.74,2638.79,0
3,2639.85,2640.01,2638.08,2638.95,0
4,2640.07,2640.87,2639.31,2639.88,0
5,2640.31,2640.48,2639.42,2640.08,0
6,2641.09,2641.09,2640.3,2640.31,0
一个有点神秘,但可以看到的柱线线与底部的数据如何。此外, F
查询参数似乎表明要返回的列(D =日,C =关闭,V =体积,O =开,H =高,L =低)。
A little cryptic, but you can see how the COLUMNS line lines up with the data at the bottom. Also, the f
querystring parameter seems to be indicating which columns to return (d=date, c=close,v=volume,o=open,h=high,l=low).
修改:我应该说我使用的URL正在从金融图形页面发送到获得更新的数据 - 你可以看到被要求在使用像小提琴手的工具定期此URL。我上面粘贴的响应数据也从MSDN示例应用程序的输出。
EDIT: I should mention that the URL I used is being sent from the finance graph page to get updated data - you can see this URL being requested at regular intervals using a tool like Fiddler. The response data that I pasted above is also output by the sample application from MSDN.
但评论指出,从MSDN和一个小摆弄提琴手的例子一行应该给你,你需要解析来自该URL返回的数据和线索。
But commenting out that one line in the example from MSDN and a little fiddling with Fiddler should give you the data and clues you need to parse the return that comes from that URL.
我希望这有助于!
PS - 在我修改MSDN例如我的第一个行看起来是这样的:
PS - my first line in my modified MSDN example looks like this:
HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)WebRequest.Create("http://www.google.com/finance/getprices?q=.IXIC&x=INDEXNASDAQ&i=120&p=10m&f=d,c,v,o,h,l&df=cpct&auto=1&ts=1307994768643");
我做了一个类似的修改其他的WebRequest
在这个例子中进一步降下来一点......除此之外,我没有在这个例子改变任何东西
I made a similar change to the other WebRequest
call a little further down in the example...other than that, I didn't change anything else in the example.
这篇关于谷歌财经,如何获得JSON数据流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!