从天气API

时间:2015-09-20 13:52:45

标签: xml excel api excel-vba vba

如何使用此API过滤Excel中特定日期的XML?:

http://api.openweathermap.org/data/2.5/forecast/daily?q=London&mode=xml&units=metric&cnt=16

B10单元格中的具体日期为2015-10-01,API提供16天预测数据。我需要获取特定日期的温度,湿度,符号名称和降水量。

我尝试使用= FILTERXML()但我找不到xpath。

1 个答案:

答案 0 :(得分:0)

应该是这样的:

enter image description here

E10向下的公式:

=FILTERXML(WEBSERVICE("http://api.openweathermap.org/data/2.5/forecast/daily?q=London&mode=xml&units=metric&cnt=16"),"/weatherdata/forecast/time[@day='"&TEXT($B$10,"YYYY-MM-DD")&"']/"&$C10&"/@"&$D10)

但是,网络服务的数据正在永久改变。

示例XML:

<weatherdata>
 <location><name>London</name><type/><country>GB</country><timezone/><location altitude="0" latitude="51.50853" longitude="-0.12574" geobase="geonames" geobaseid="2643743"/></location><credit/><meta><lastupdate/><calctime>0.0117</calctime><nextupdate/></meta><sun rise="2015-09-20T05:43:44" set="2015-09-20T18:02:55"/>

 <forecast>
  <time day="2015-09-20">
    <symbol number="800" name="sky is clear" var="01d"/>
    <precipitation/>
    <windDirection deg="243" code="WSW" name="West-southwest"/>
    <windSpeed mps="3.96" name="Gentle Breeze"/>
    <temperature day="19.43" min="12.68" max="19.73" night="12.68" eve="17.24" morn="19.43"/>
    <pressure unit="hPa" value="1031.17"/>
    <humidity value="80" unit="%"/>
    <clouds value="clear sky" all="0" unit="%"/>
  </time>

XPATH到白天的温度2015-09-20:

/weatherdata/forecast/time[@day='2015-09-20']/temperature/@day