Получить конкретный элемент из XML из URL Python - PullRequest
0 голосов
/ 26 октября 2019

Я пытаюсь получить определенный элемент в XML-файле из URL, используя ElementTree. Я пытаюсь получить количество осадков на основе определенной даты.

Я могу перебирать количество осадков и время по отдельности, но я не знаю, как получить количество осадков на основе времени.

XML-файл:

    <weatherdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:noNamespaceSchemaLocation="http://api.met.no/weatherapi/locationforecast/1.9/schema" created="2019-10-24T15:20:55Z">
<meta>
<model name="harmonie" termin="2019-10-24T06:00:00Z" runended="2019-10-24T09:33:12Z" nextrun="2019-10-24T16:00:00Z" from="2019-10-24T16:00:00Z" to="2019-10-26T12:00:00Z"/>
<model name="ec_n1280_1hr" termin="2019-10-24T00:00:00Z" runended="2019-10-24T09:33:12Z" nextrun="2019-10-24T18:00:00Z" from="2019-10-26T13:00:00Z" to="2019-10-27T18:00:00Z"/>
<model name="ec_n1280_3hr" termin="2019-10-24T00:00:00Z" runended="2019-10-24T09:33:12Z" nextrun="2019-10-24T18:00:00Z" from="2019-10-27T21:00:00Z" to="2019-10-30T00:00:00Z"/>
<model name="ec_n1280_6hr" termin="2019-10-24T00:00:00Z" runended="2019-10-24T09:33:12Z" nextrun="2019-10-24T18:00:00Z" from="2019-10-30T06:00:00Z" to="2019-11-03T00:00:00Z"/>
</meta>
<product class="pointData">
<time datatype="forecast" from="2019-10-24T16:00:00Z" to="2019-10-24T16:00:00Z">
<location altitude="41" latitude="53.3639" longitude="-6.3333">
<temperature id="TTT" unit="celsius" value="9.8"/>
<windDirection id="dd" deg="327.6" name="NW"/>
<windSpeed id="ff" mps="4.4" beaufort="3" name="Lett bris"/>
<humidity value="87.2" unit="percent"/>
<pressure id="pr" unit="hPa" value="1004.5"/>
<cloudiness id="NN" percent="94.9"/>
<lowClouds id="LOW" percent="84.4"/>
<mediumClouds id="MEDIUM" percent="64.1"/>
<highClouds id="HIGH" percent="0.0"/>
<dewpointTemperature id="TD" unit="celsius" value="7.8"/>
</location>
</time>
<time datatype="forecast" from="2019-10-24T15:00:00Z" to="2019-10-24T16:00:00Z">
<location altitude="41" latitude="53.3639" longitude="-6.3333">
<precipitation unit="mm" value="1.0" minvalue="0.5" maxvalue="1.3"/>
<symbol id="Rain" number="10"/>
</location>
</time>
<time datatype="forecast" from="2019-10-24T17:00:00Z" to="2019-10-24T17:00:00Z">
<location altitude="41" latitude="53.3639" longitude="-6.3333">
<temperature id="TTT" unit="celsius" value="8.7"/>
<windDirection id="dd" deg="323.1" name="NW"/>
<windSpeed id="ff" mps="2.4" beaufort="2" name="Svak vind"/>
<humidity value="85.3" unit="percent"/>
<pressure id="pr" unit="hPa" value="1005.1"/>
<cloudiness id="NN" percent="96.3"/>
<lowClouds id="LOW" percent="90.1"/>
<mediumClouds id="MEDIUM" percent="61.7"/>
<highClouds id="HIGH" percent="0.0"/>
<dewpointTemperature id="TD" unit="celsius" value="6.3"/>
</location>
</time>
<time datatype="forecast" from="2019-10-24T16:00:00Z" to="2019-10-24T17:00:00Z">
<location altitude="41" latitude="53.3639" longitude="-6.3333">
<precipitation unit="mm" value="0.2" minvalue="0.0" maxvalue="0.5"/>
<symbol id="Drizzle" number="46"/>
</location>
</time>



for precip in xroot.iter('precipitation'):
     print(precip.attrib)

Я хочу получить доступ к осадкам на основе

<time datatype="forecast" from="2019-10-24T15:00:00Z" to="2019-10-    24T16:00:00Z">
...