【问题标题】:Filter the XML for specific date from weather API从天气 API 过滤特定日期的 XML
【发布时间】:2015-09-20 13:52:45
【问题描述】:

如何通过此 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。

【问题讨论】:

    标签: xml api excel vba


    【解决方案1】:

    应该是这样的:

    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 年 9 月 20 日当天的温度:

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

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 2022-08-02
      • 2020-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 2020-04-25
      • 2011-01-04
      相关资源
      最近更新 更多