How can I get data from a site like Yahoo Finance?

phan picture phan · Dec 2, 2011 · Viewed 20.5k times · Source

I have a project that I need help with. I want to be able to go to a website of my making, e.g. abc123.com, and have it display the Dow Jones Index. That's it. Just display one number like 12050 on my abc123.com website.

Obviously I have to get the data from somewhere like Yahoo Finance. I don't want to download any .csv files or anything like that. And it doesn't need to be real time data since I know Yahoo's data is 15 minutes delayed. Just want to be able to visit my own site and see what the Dow Jones Index is.

Before asking this question I did research some similar questions on SO, but a lot of them were unanswered or references YQL (something I'm looking into and trying to comprehend at this moment).

Any guidance on the simplest way to do this would be greatly appreciated! I am a beginning programmer in HTML and am looking for the easiest-to-understand-and-implement route.

Answer

Andrew Rasmussen picture Andrew Rasmussen · Dec 2, 2011

You can't. Not programmatically, but legally.

Quotes delayed, except where indicated otherwise. Delay times are 15 mins for NASDAQ, NYSE and Amex. See also delay times for other exchanges. Quotes and other information supplied by independent providers identified on the Yahoo! Finance partner page. Quotes are updated automatically, but will be turned off after 25 minutes of inactivity. Quotes are delayed at least 15 minutes. All information provided "as is" for informational purposes only, not intended for trading purposes or advice. Neither Yahoo! nor any of independent providers is liable for any informational errors, incompleteness, or delays, or for any actions taken in reliance on information contained herein. By accessing the Yahoo! site, you agree not to redistribute the information found therein.

All of the major market data providers have some sort of legal stuff like that.

But if you were going to do it anyways, I would probably download the html and parse it in order to find the quote you're looking for.

If you want to do it legally you're going to have to pay a lot of money to get the data from either the exchange itself or a third party entity that relays the information. In that case you're going to have to use whatever API they provide.

Sources: trying to do what you're thinking about doing :)

(EDIT) To those who say use YQL:

Take a look at the Terms of Use.

You can not:

Sell, lease, share, transfer, or sublicense YQL or derive income from the use of YQL in conjunction with Yahoo! APIs or other web services, whether for direct commercial or monetary gain or otherwise, without Yahoo!'s prior, express, written permission

or

Use YQL in a product or service that competes with products or services offered by Yahoo!

Any site that is sharing stock quotes is going to be competing with finance.yahoo.com and therefore disobeying the terms of use of YPL. Furthermore, you won't be able to make any money off of what you're doing with this data. Good luck getting express written consent.

Read under "The Dark Side" here on YQL too: "who owns my code? Technically, they own everything."

YQL isn't a good solution in terms of scalability, profitability, simplicity, or legality. If you don't care about any of these things and your web application isn't going to be popular or make you money, and you don't mind writing a bunch of code to play nicely with Yahoo! then YQL is the way to go.

(EDIT #2)

If you are just trying to display the information for yourself (not sharing it with others), I find it extremely easy to parse html and display it on a website with C#/Visual Basic and ASP.NET rather than php. You can create an http request in C#/VB which will (eventually) return an html file, which you can parse or search through for your Dow Jones Index quote. Do this all in C#/VB as the back end of an ASP web application. I believe you can create these with Visual Studio 2010 Express which is free.