You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python3:从XML中提取指定站点的UV-index值

提取指定站点的UV指数值

以下是几种从目标XML文件中提取Roomassaare站点UV指数的实用方法:

Python 脚本实现

使用Python内置的XML解析库直接获取数据:

import xml.etree.ElementTree as ET
import urllib.request

# 获取并解析XML数据
with urllib.request.urlopen("https://www.ilmateenistus.ee/ilma_andmed/xml/observations.php") as response:
    root = ET.fromstring(response.read())

# 定位目标站点并提取UV指数
for station in root.findall("station"):
    station_name = station.find("name").text
    if station_name == "Roomassaare":
        uv_index = station.find("uvindex").text
        print(f"Roomassaare的UV指数:{uv_index}")
        break

命令行工具实现

方法1:curl + xmllint

适用于Linux/macOS系统(需安装xmllint):

curl -s "https://www.ilmateenistus.ee/ilma_andmed/xml/observations.php" | xmllint --xpath '//station[name="Roomassaare"]/uvindex/text()' -

方法2:curl + xq(yq工具集)

需先安装xq(属于yq工具集):

curl -s "https://www.ilmateenistus.ee/ilma_andmed/xml/observations.php" | xq '.observations.station[] | select(.name == "Roomassaare") | .uvindex'

内容的提问来源于stack exchange,提问作者fred

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 23:02:11