javascript - YQL 天气声明未显示某些物体,例如日出、日落和风寒

标签 javascript xml yql

您好,我正在使用该声明

    SELECT * FROM rss WHERE url="http://xml.weather.yahoo.com/forecastrss/SPXX0239_c.xml"

我获得了 5 天的预测数据,其中包含日期、图标、温度和文本,这非常棒。不过,我想获取其他信息,例如风寒、日出/日落以及温度感觉。我在请求中看不到它们?

这是我的数据回调

    window['wCallback_2'] = function(data) {
// Get todays weather forecast
     var info = data.query.results.item.forecast[0];
     var code = info.code;
$('#wData_current .wDate_d').append('<TD>' + info.date) + '</TD>';
    $('#wData_current .wDay_d').append('<TD>' + info.day) + '</TD>';
    $('#wData_current .wIcon_d').append('<TD> <img src="http://l.yimg.com/a/i/us/we/52/' + code + '.gif" width="80" height="80" title="' + info.text + '" /> </TD>');
$('#wData_current .wText_d').append('<TD>' + info.text + '</TD>');
    $('#wData_current .wHigh').append('<TD>' + info.high + '&deg;' + u + '</TD>');
    $('#wData_current .wLow').append('<TD>' + info.low + '&deg;' + u + '</TD>');

};

最佳答案

rss表只提供 <item> 内的内容元素。由于 RSS 是普通的旧式 XML,因此 xml可以使用表格来代替。

SELECT * FROM xml
WHERE url="http://xml.weather.yahoo.com/forecastrss/SPXX0239_c.xml"
AND itemPath="rss.channel.*"

会给你一个data对象结构如下:

{
 "query": {
  …
  "results": {
   "title": "Yahoo! Weather - Lanzarote, SP",
   …
   "location": { … },
   "units": { … },
   "wind": {
    "chill": "19",
    "direction": "20",
    "speed": "32.19"
   },
   "atmosphere": { … },
   "astronomy": {
    "sunrise": "7:29 am",
    "sunset": "8:19 pm"
   },
   "image": { … },
   "item": {
    "title": "Conditions for Lanzarote, SP at 8:59 pm WEST",
    "lat": "28.95",
    "long": "-13.6",
    "link": … ,
    "pubDate": "Mon, 15 Apr 2013 8:59 pm WEST",
    "condition": { … },
    "description": … ,
    "forecast": [ … ],
    "guid": { … }
   }
  }
 }
}

要访问日出时间,您可以使用 data.query.results.astronomy.sunrise .

关于javascript - YQL 天气声明未显示某些物体,例如日出、日落和风寒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16018339/

相关文章:

javascript - 加深十六进制颜色不起作用

javascript - 检查 jquery 选择的对象数组中的元素名称

javascript - 将变量的值传递给 angularjs 指令模板函数

javascript - ActiveX 对象错误

Python HTTP 错误 505 : HTTP Version Not Supported

xml - 闪存 AS3 : XML and undefined values

javascript - 使用 JavaScript 从另一个网站获取 div 的内容

c# - 我的oauth2回调页面可以是同一个html页面吗?我如何获得 token ?

xml - 使用 powershell 脚本分析 XML 文件

python - 如何通过python3改变xml中元素属性的值