我有使用codeigniter作为框架的PHP代码,所有正在做的就是从Google股票中获取最新信息:
{ section name="company" loop=$stock}
<hr noshade size="1" width="100%">
<table width="100%" border="0">
<tr>
<td colspan="5"><b>{$stock[company].symbol}: {$stock[company].name}</b></td>
</tr>
<tr>
{if $stock[company].symbol == "Google"}
<td><b><a href="http://www.nasdaq.com/asp/quotes_multi.asp?mode=stock&symbol=googl">Google - NASDAQ</a></b></td>
{else}
<td> </td>
{/if}
<td colspan="4"><div align="right">{$stock[company].date},
{if $stock[company].time != ""}
{$stock[company].time|date_format:"%I:%M%p"} ET
{/if}
{if $stock[company].status != ""}
- {$stock[company].status}
{/if}</div></td>
</tr>
<tr>
<td>Last Sale:</td>
<td><div align="right"><b>$ {$stock[company].price_last}</b></div></td>
<td> </td>
<td>Net Change:</td>
<td><div align="right">$ {$stock[company].dchangeu}
{if $stock[company].direction == "up"}
<img src="/images/greenArrowSmall.gif" alt="" height="11" width="11" alt="^"> {$stock[company].pchange}%
{else if $stock[company].direction == "down"}
<img src="/images/redArrowSmall.gif" alt="" height="11" width="11" alt="v"> {$stock[company].pchange}%
{/if}
</div></td>
</tr>
<tr>
<td>Today's High:</td>
<td><div align="right">$ {$stock[company].price_max|string_format:"%.2f"}</div></td>
<td> </td>
<td>Today's Low:</td>
<td><div align="right">$ {$stock[company].price_min|string_format:"%.2f"}</div></td>
</tr>
<tr>
<td>Share Volume:</td>
<td><div align="right">{$stock[company].volume}</div></td>
<td> </td>
<td>Previous Close:</td>
<td><div align="right">$ {$stock[company].previous|string_format:"%.2f"}</div></td>
</tr>
<tr>
<td>Best Bid:</td>
{if $stock[company].best_bid != ""}
<td><div align="right">$ {$stock[company].best_bid|string_format:"%.2f"}</div></td>
{else}
<td><div align="right">unavailable</div></td>
{/if}
<td> </td>
<td>Best Ask:</td>
{if $stock[company].best_ask != ""}
<td><div align="right">$ {$stock[company].best_ask|string_format:"%.2f"}</div></td>
{else}
<td><div align="right">unavailable</div></td>
{/if}
</tr>
</table>
{/section}
该代码使用的URL似乎不再存在:http://www.nasdaq.com/asp/quotes_multi.asp?mode=stock&symbol=googl因为它会返回“找不到”响应。
我不认为纳斯达克将使该.asp页可用,因为我读到ASP很旧,因此,对代码进行最少更改的最佳解决方案是什么?
我用google搜索是否有其他网站提供该asp页面,但没有一个,只有API返回JSON格式的数据,如果我想对其进行更新以获取JSON变量,这会对我的代码产生很大的影响。还有其他选择吗?
非常感谢您。
您提供的URL现在可能是this one。但是我怀疑您的真正兴趣是填充$stock
变量。
解析json数据实际上很容易,因此对代码的影响可能没有您想像的那么大。