阅读新 "query.yahooapis.com" 天气 XML
Read NEW "query.yahooapis.com" weather XML
我曾经使用下面的代码来检索当前温度。但它不再起作用了。
Set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = "false"
objXML.setProperty "ServerHTTPRequest", true
objXML.load("http://weather.yahooapis.com/forecastrss?p=79105&u=f")
outTEMPer = objXML.selectSingleNode("//item/yweather:condition").Attributes.GetNamedItem("temp").Text
新Link是
objXML.load("https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text%3D%22amarillo%2C tx%22)&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys")
但是我无法解析当前温度。试过
outTEMPer = objXML.selectSingleNode("//item/yweather:condition").Attributes.GetNamedItem("temp").Text
和
outTEMPer = objXML.getElementsByTagName("http://xml.weather.yahoo.com/ns/rss/1.0","condition").getAttribute("temp")
XML 是:
<?xml version="1.0" encoding="UTF-8"?>
<query yahoo:lang="en-us" yahoo:created="2016-03-29T14:50:40Z" yahoo:count="1" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng">
<!-- total: 19 -->
<!-- main-1f117507-f23e-11e5-8580-d89d676f9644 -->
<results>
<channel>
<yweather:units temperature="F" speed="mph" pressure="in" distance="mi" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"/>
<title>Yahoo! Weather - Amarillo, TX, US</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2354141/</link>
<description>Yahoo! Weather for Amarillo, TX, US</description>
<language>en-us</language>
<lastBuildDate>Tue, 29 Mar 2016 09:50 AM CDT</lastBuildDate>
<ttl>60</ttl>
<yweather:location xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" region=" TX" country="United States" city="Amarillo"/>
<yweather:wind speed="18" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" direction="175" chill="52"/>
<yweather:atmosphere pressure="26.13405" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" visibility="10.004077" rising="0" humidity="75"/>
<yweather:astronomy xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" sunset="8:7 pm" sunrise="7:37 am"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
</image>
<item>
<title>Conditions for Amarillo, TX, US at 09:00 AM CDT</title>
<geo:lat xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">35.207249</geo:lat>
<geo:long xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">-101.833893</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2354141/</link>
<pubDate>Tue, 29 Mar 2016 09:00 AM CDT</pubDate>
<yweather:condition xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" text="Breezy" temp="57" date="Tue, 29 Mar 2016 09:00 AM CDT" code="23"/>
下面的XML代码就是我需要的
谢谢阿瑞斯。成功了。
XML 使用命名空间。可以像这样选择命名空间节点(及其属性):
uri = "http://xml.weather.yahoo.com/ns/rss/1.0"
objXML.SetProperty "SelectionNamespaces", "xmlns:ns='" & uri & "'"
outTEMPer = objXML.SelectSingleNode("//item/ns:condition").GetAttribute("temp")
不要费力,也不要更改您以前的代码。 http://weather.yahooapis.com/forecastrss 不再有效,但它并没有消失。
只是改成了http://xml.weather.yahoo.com/forecastrss
您可以将应用程序中的 link 更改为新地址,它将 return 与前者完全相同的数据。
我在 Arduino 中实现了这个调用,几天前它停止工作了。通过 webz 搜索后,我发现他们已经更改了地址。我复制并粘贴它,它又像新的一样工作了。
更新:
截至 2016 年 5 月 27 日,http://xml.weather.yahoo.com/forecastrss URL 不再有效,出现 "Could not connect to server" 错误。
我曾经使用下面的代码来检索当前温度。但它不再起作用了。
Set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = "false"
objXML.setProperty "ServerHTTPRequest", true
objXML.load("http://weather.yahooapis.com/forecastrss?p=79105&u=f")
outTEMPer = objXML.selectSingleNode("//item/yweather:condition").Attributes.GetNamedItem("temp").Text
新Link是
objXML.load("https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text%3D%22amarillo%2C tx%22)&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys")
但是我无法解析当前温度。试过
outTEMPer = objXML.selectSingleNode("//item/yweather:condition").Attributes.GetNamedItem("temp").Text
和
outTEMPer = objXML.getElementsByTagName("http://xml.weather.yahoo.com/ns/rss/1.0","condition").getAttribute("temp")
XML 是:
<?xml version="1.0" encoding="UTF-8"?>
<query yahoo:lang="en-us" yahoo:created="2016-03-29T14:50:40Z" yahoo:count="1" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng">
<!-- total: 19 -->
<!-- main-1f117507-f23e-11e5-8580-d89d676f9644 -->
<results>
<channel>
<yweather:units temperature="F" speed="mph" pressure="in" distance="mi" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"/>
<title>Yahoo! Weather - Amarillo, TX, US</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2354141/</link>
<description>Yahoo! Weather for Amarillo, TX, US</description>
<language>en-us</language>
<lastBuildDate>Tue, 29 Mar 2016 09:50 AM CDT</lastBuildDate>
<ttl>60</ttl>
<yweather:location xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" region=" TX" country="United States" city="Amarillo"/>
<yweather:wind speed="18" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" direction="175" chill="52"/>
<yweather:atmosphere pressure="26.13405" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" visibility="10.004077" rising="0" humidity="75"/>
<yweather:astronomy xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" sunset="8:7 pm" sunrise="7:37 am"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
</image>
<item>
<title>Conditions for Amarillo, TX, US at 09:00 AM CDT</title>
<geo:lat xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">35.207249</geo:lat>
<geo:long xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">-101.833893</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2354141/</link>
<pubDate>Tue, 29 Mar 2016 09:00 AM CDT</pubDate>
<yweather:condition xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" text="Breezy" temp="57" date="Tue, 29 Mar 2016 09:00 AM CDT" code="23"/>
下面的XML代码就是我需要的
谢谢阿瑞斯。成功了。
XML 使用命名空间。可以像这样选择命名空间节点(及其属性):
uri = "http://xml.weather.yahoo.com/ns/rss/1.0"
objXML.SetProperty "SelectionNamespaces", "xmlns:ns='" & uri & "'"
outTEMPer = objXML.SelectSingleNode("//item/ns:condition").GetAttribute("temp")
不要费力,也不要更改您以前的代码。 http://weather.yahooapis.com/forecastrss 不再有效,但它并没有消失。
只是改成了http://xml.weather.yahoo.com/forecastrss 您可以将应用程序中的 link 更改为新地址,它将 return 与前者完全相同的数据。 我在 Arduino 中实现了这个调用,几天前它停止工作了。通过 webz 搜索后,我发现他们已经更改了地址。我复制并粘贴它,它又像新的一样工作了。
更新: 截至 2016 年 5 月 27 日,http://xml.weather.yahoo.com/forecastrss URL 不再有效,出现 "Could not connect to server" 错误。