我正在尝试从 yql 生成的 xml 中获取 id "yfs_a00_xauusd=x" 的数据。
我试过这个..但结果是
问:真http://finance.yahoo.com/q?s=XAGUSD%3DX&ql=1 613 600 27426 28.3600 我只想抢28.3600
<?php
session_start();
$yql_base_url = "http://query.yahooapis.com/v1/public/yql";
$xpath='//*[@id="yfs_g00_xagusd=x"]';
$url = 'http://finance.yahoo.com/q?s=XAGUSD%3DX&ql=1';
$yql_query = "select * from html where url=$url and xpath = $xpath;";
$yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
$yql_query_url .= "&env=http://datatables.org/alltables.env";
$yql_query_url .= "&format=json";
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
$phpObj = json_decode($json);
if(!is_null($phpObj->query->results->span)){
foreach($phpObj->query->results->span as $result){
$_SESSION['price'] = $result;
}
}
?>
<div> Ask:<?php echo $_SESSION['span'];?> </div>
yahoo生成的XML是....
<query yahoo:count="1" yahoo:created="2012-05-16T19:00:25Z" yahoo:lang="en-US">
<diagnostics>
<publiclyCallable>true</publiclyCallable>
<url execution-start-time="1" execution-stop-time="601" execution-time="600" proxy="DEFAULT">http://finance.yahoo.com/q?s=XAGUSD%3DX&ql=1</url>
<user-time>613</user-time>
<service-time>600</service-time>
<build-version>27426</build-version>
</diagnostics>
<results><span id="yfs_g00_xagusd=x">28.3600</span></results>
</query>
我真的很感谢你的帮助..提前谢谢。