How can I get data from a site, for example, Yahoo Finance?

I have a project that I need help with. I want to be able to go to the site of my creation, for example. abc123.com, and display the Dow Jones index. It. Just show one number, for example, 12050 on my website abc123.com.

Obviously, I need to get data from somewhere like Yahoo Finance. I do not want to download any CSV files or anything like that. And this does not have to be real-time data, since I know that Yahoo data is delayed for 15 minutes. I just want to be able to visit my own site and see what the Dow Jones index is.

Before asking this question, I studied some similar questions on SO, but many of them were left unanswered or referred to YQL (something that I am studying and trying to understand at the moment).

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

+4
source share
4 answers

You can not. Not programmatically, but legally.

Delays, unless otherwise indicated. The delay time is 15 minutes for NASDAQ, NYSE and Amex. See also delay time for other exchanges. Quotations and other information provided by third parties listed on Yahoo! Page of a financial partner. Quotes are updated automatically, but will be disabled after 25 minutes of inactivity. Quotes are held for at least 15 minutes. All information provided "as is" is for informational purposes only and not for trading purposes or recommendations. None of Yahoo! none of the third-party providers is liable for any informational errors, incompleteness or delays, or for any actions taken in connection with the information contained in this document. Access to Yahoo! of the site, you agree not to disseminate the information found in it.

All major market data providers are of some legal nature.

But if you are going to do it anyway, I would probably download the html and parse it to find the right quote.

If you want to do this legally, you will have to pay a lot of money to get data from the tag itself or a third-party organization that transmits the information. In this case, you will have to use any API that they provide.

Sources: you are trying to do what you think:

(EDIT) For those who speak, use YQL:

Take a look at the Terms of Use.

You can not:

Sell, rent, share, transfer or sublicense YQL or earn revenue from using YQL in conjunction with Yahoo! API or other web services , whether for direct commercial or monetary gain or otherwise, without Yahoo! express written permission

or

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

Any site that shares stock quotes is going to compete with finance.yahoo.com and therefore does not comply with the terms of use of YPL. In addition, you will not be able to make any money from what you do with this data. Good luck getting written consent.

Read in the "Dark Side" section here on YQL: "Who owns my code? Technically, they own everything."

YQL is not 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 will not be popular or will make you money, and you do not mind writing a bunch of code to play well with Yahoo! then YQL is the way to go.

(EDIT # 2)

If you are just trying to display information for yourself (do not share it with others), it is very easy for me to parse html and display it on a website using C # / Visual Basic and ASP.NET, not php. You can create an HTTP request in C # / VB, which (ultimately) will return an html file that you can parse or search for your Dow Jones index quote. Do it all in C # / VB as the back of your ASP web application. I believe that you can create them using Visual Studio 2010 Express, which is free.

+3
source

I am not sure if there is a legal limit to this. There are many commercial (paid) applications that extract data from Yahoo Finance and have worked great for many years. I would say that the trick is that these applications are installed on the user device (iOS / Android / Windows devices), and therefore they extract data from Yahoo Finance for personal use by the user.

Perhaps if you pulled data from Yahoo Finance through Javascript and did not save it on your servers, the same case applies to your project. In fact, I would have thought so. The only difference in this case is that your code will not need to be installed on the user device, as this is a web page.

Have you tried contacting YQL or Yahoo Finance to discuss the legal limitations of your projects?

+1
source

I wrote a function to get stock data from Yahoo! Financial API however, my code loads the .csv file. Hope this will be helpful.

Full source code and sample results are on my blog .

<?php /* Description: Getting Stock Data from Yahoo! Finance Author URI: http://phpvancouver.ca/ */ /* * More about Yahoo! Finance Tag * http://www.gummy-stuff.org/Yahoo-data.htm * http://www.canbike.ca/information-technology/2013/08/10/yahoo-finance-url-download-to-a-csv-file.html */ $yahoo_finance_tags = array( "a" => "Ask", "a2" => "Average Daily Volume", "a5" => "Ask Size", "b" => "Bid", "b2" => "Ask (Real-time)", "b3" => "Bid (Real-time)", "b4" => "Book Value", "b6" => "Bid Size", "c" => "Change & Percent Change", "c1" => "Change", "c3" => "Commission", "c6" => "Change (Real-time)", "c8" => "After Hours Change (Real-time)", "d" => "Dividend/Share", "d1" => "Last Trade Date", "d2" => "Trade Date", "e" => "Earnings/Share", "e1" => "Error Indication (returned for symbol changed / invalid)", "e7" => "EPS Estimate Current Year", "e8" => "EPS Estimate Next Year", "e9" => "EPS Estimate Next Quarter", "f6" => "Float Shares", "g" => "Day Low", "h" => "Day High", "j" => "52-week Low", "k" => "52-week High", "g1" => "Holdings Gain Percent", "g3" => "Annualized Gain", "g4" => "Holdings Gain", "g5" => "Holdings Gain Percent (Real-time)", "g6" => "Holdings Gain (Real-time)", "i" => "More Info", "i5" => "Order Book (Real-time)", "j1" => "Market Capitalization", "j3" => "Market Cap (Real-time)", "j4" => "EBITDA", "j5" => "Change From 52-week Low", "j6" => "Percent Change From 52-week Low", "k1" => "Last Trade (Real-time) With Time", "k2" => "Change Percent (Real-time)", "k3" => "Last Trade Size", "k4" => "Change From 52-week High", "k5" => "Percebt Change From 52-week High", "l" => "Last Trade (With Time)", "l1" => "Last Trade (Price Only)", "l2" => "High Limit", "l3" => "Low Limit", "m" => "Day Range", "m2" => "Day Range (Real-time)", "m3" => "50-day Moving Average", "m4" => "200-day Moving Average", "m5" => "Change From 200-day Moving Average", "m6" => "Percent Change From 200-day Moving Average", "m7" => "Change From 50-day Moving Average", "m8" => "Percent Change From 50-day Moving Average", "n" => "Name", "n4" => "Notes", "o" => "Open", "p" => "Previous Close", "p1" => "Price Paid", "p2" => "Change in Percent", "p5" => "Price/Sales", "p6" => "Price/Book", "q" => "Ex-Dividend Date", "r" => "P/E Ratio", "r1" => "Dividend Pay Date", "r2" => "P/E Ratio (Real-time)", "r5" => "PEG Ratio", "r6" => "Price/EPS Estimate Current Year", "r7" => "Price/EPS Estimate Next Year", "s" => "Symbol", "s1" => "Shares Owned", "s7" => "Short Ratio", "t1" => "Last Trade Time", "t6" => "Trade Links", "t7" => "Ticker Trend", "t8" => "1 yr Target Price", "v" => "Volume", "v1" => "Holdings Value", "v7" => "Holdings Value (Real-time)", "w" => "52-week Range", "w1" => "Day Value Change", "w4" => "Day Value Change (Real-time)", "x" => "Stock Exchange", ); /* This function gets a symbol or an array of symbol as a parameter. * And it returns an array of the corresponding stock data. * If an error occurs, the detail of the error is saved in $error_message variable * which is passed by reference from the parent function */ function get_stock_data_from_yahoo_finance_pv($symbol, &$error_message) { global $yahoo_finance_tags; $error_message = NULL; // Default value $f = ""; // The f parameter in Yahoo! Finance URL foreach($yahoo_finance_tags as $key => $value) $f = $f . $key; if ( is_array($symbol) ) { // if the symbol is an array if ( $symbol == NULL ) { // if the symbol is invalid $error_message = "The given symbol is invalid."; return -1; // ERROR } $url = "http://finance.yahoo.com/d/quotes.csv?s=" . implode("+", $symbol) . "&f=" . $f; $fp = @fopen($url, "r"); if ( $fp == FALSE ) { // If the URL can't be opened $error_message = "Cannot get data from Yahoo! Finance. The following URL is not accessible, $url"; return -1; // ERROR } $arr = array(); $symbol = explode("+",implode("+", $symbol)); // Eliminate the keys in the symbol array $j = 0; while ( ($array = @fgetcsv($fp , 4096 , ', ')) !== FALSE ) { $i = 0; $p = array(); foreach($yahoo_finance_tags as $key => $value) { $p[$key] = $array[$i]; $i = $i + 1; } $arr[$symbol[$j]]= $p; $j = $j + 1; } @fclose($fp); return $arr; } else { // if the symbol is not array if ( strlen($symbol) < 1 || $symbol == NULL ) { // if the symbol is invalid $error_message = "The given symbol is invalid."; return -1; // ERROR } $url = "http://finance.yahoo.com/d/quotes.csv?s=" . $symbol . "&f=" . $f; $fp = @fopen($url, "r"); if ( $fp == FALSE ) { // If the URL can't be opened $error_message = "Cannot get data from Yahoo! Finance. The following URL is not accessible, $url"; return -1; // ERROR } $array = @fgetcsv($fp , 4096 , ', '); $arr = array(); $i = 0; foreach($yahoo_finance_tags as $key => $value) { $arr[$key] = $array[$i]; $i = $i + 1; } @fclose($fp); return $arr; } return -1; } 
+1
source

Thanks to everyone who contributed, because the ideas created in this thread helped me find the answer and do EXACTLY what I was looking for. This guy explains how to do this in about 10 lines of code:

http://www.seangw.com/wordpress/index.php/2010/01/formatting-stock-data-from-yahoo-finance/

So basically all I did was cut and paste its code and put it in index.html on my site. When I visit my website, I get quotes with tickers that interest me. You can change the $ stocklist to accommodate any stock you want, and you can change the response from Yahoo using the tags in $ stockFormat. Thanks again SO!

0
source

Source: https://habr.com/ru/post/1384390/


All Articles