php - 从不再存在的 ASP 网站获取股票数据有哪些选择?
问题描述
我有这个使用 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,因为它返回“未找到”响应。
我认为 nasdaq 不会提供这个 .asp 页面,因为我读到 ASP 已经过时了,对代码进行最少更改的最佳解决方案是什么?
我搜索了是否有任何其他网站提供该 asp 页面,但没有,只有 API 以 JSON 格式返回数据,如果我想更新它以获取 JSON 变量,这将对我的代码产生很大影响,有没有其他选择吗?
非常感谢你。
解决方案
您现在提供的 URL 可能是这个。但我怀疑你真正的兴趣是填充$stock
变量。
解析json数据其实很简单,所以对你的代码的影响可能没有你想象的那么大。
推荐阅读
- apache-spark - Pyspark 轮函数未按预期工作
- android - What is the appropriate way of calling suspending functions inside a suspendCoroutine block?
- python - UnboundLocalError:分配前引用的局部变量“文本”
- pytorch - PyTorch:从坐标张量到网格张量的可微操作
- c# - 在下面描述的情况下,PictureBox 或 Label 可能无法显示它们各自的图像或文本的一些原因是什么?
- databricks - 列出 DBFS 文件存储中文件的内容
- sql - 比较与另一行中的更改相对应的列中的日期
- javascript - 承诺/异步/等待功能不等待响应的问题
- java - maven-shade-plugin 会在“import”中排除重命名类的位置吗?
- python - 具有 CDATA 的 Python Xml 解析