PHP Parsing Conundrum - "Missing Symbols Listed"
I am trying to access the Yahoo site by getting Stock quotes:
http://de.finance.yahoo.com/d/quotes.csv?s=^DJI&f=nsl1op&e=.csv
and it doesn't seem to be downloading any data. I get "Missing Symbols Listed.". Weird b/c this used to work!
<?php
function market_value($s) {
$records= fopen ("http://quote.yahoo.com/d/quotes.csv?s=$s&f=nsl1&e=.csv");
$contents = fread ($records);
fclose ($records);
$data = str_replace ("\"", "", $data);
$data = expl开发者_StackOverflowode (",", $data);
$trade= $data[2];
return (".$trade.")";
}
^DJI
can not be queried from yahoo, as it seems. You should use INDU
. Try downloading
http://finance.yahoo.com/d/quotes.csv?s=INDU,GOOG,MSFT&f=nsl1op&e=.csv
This should return something like
"Dow Jones Industr","^DJI",12069.94,12057.34,12058.02
"Google Inc.","GOOG",601.74,600.06,600.76
"Microsoft Corpora","MSFT",26.13,26.10,26.16
Try getting the DJI quote from Googles HTML
This is an inefficient example in .NET C# (dont know php):
public async Task<string> MakeGoogleDJIWebRequest()
{
string response = await _httpClient.GetStringAsync("http://www.google.com/finance?q=DJI");
string [] myString = Regex.Split(response, "<span id=\"ref_983582_l\">");
string [] myString2 = Regex.Split(myString[1], "</span>");
string [] myString3 = Regex.Split(response, "ref_983582_c\">");
string [] plusOrMinus = Regex.Split(myString3[1], "</span>");
string DJI = myString2[0]+ " " + plusOrMinus[0];
return DJI;
}
If you just want the value of the DJI and not the +./- just dont add the plusOrMinus[0] above to the return string.
精彩评论