无法从雅虎天气api提取描述标签
问题描述:
当我尝试从我的雅虎天气api提取描述时,我遇到了问题,我认为问题可能是找到确切的路径。无法从雅虎天气api提取描述标签
<?php
\t $url ="https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(55844479)%20where%20text%3D%22Riga%2C%20Lv%22)&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
\t $error = "";
\t $file = fopen($url, "r");
\t
\t if($file == false)
\t {
\t \t $error = "File open error";
\t }
\t else
\t {
\t \t $stringXML = "";
\t \t while (feof($file)==false)
\t \t {
\t \t \t $stringXML.= fread($file, 8192);
\t \t }
\t \t $xml = new SimpleXMLElement($stringXML);
\t \t fclose($file);
\t \t $description = $xml->results->link->description;
\t }
?>
<html>
\t <head>
\t \t <title>Yahoo weather API</title>
\t </head>
\t <body>
\t
\t \t <h1>Yahoo weather api</h1>
<?php
\t if($error == "")
\t {
\t \t echo "<h3>Description:".$description."</h3>";
\t }
\t else
\t {
\t echo "<p>".$error."</p>";
\t }
?> \t
\t </body>
</html>
任何人的头脑帮助我? :)
答
该描述不在链接中。用途:
$description = $xml->results->channel->description;
要使用CDATA获得描述里面的物品标签,使用:
$description = $xml->results->channel->item->description;
谢谢!然而,我需要第二个描述标签,其中包含cdata :) –
它在*项目*,所以它会是$ description = $ xml-> results-> channel-> item-> description;查看编辑@RalfsR – eeetee
非常感谢,现在工作很好! –