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

求助:Google Sheets IMPORTXML解析美国财政部XML Feed的XPath问题

解决Google Sheets IMPORTXML解析美国国债收益率XML命名空间问题

一、获取指定日期的<properties>内容

由于Google Sheets的IMPORTXML不支持直接使用XML命名空间前缀(如m:),需通过local-name()函数匹配标签本地名称来绕开限制,公式如下:

=IMPORTXML("https://home.treasury.gov/resource-center/data-chart-center/interest-rates/pages/xml?data=daily_treasury_yield_curve&field_tdr_date_value_month=202502", "//*[local-name()='properties' and *[local-name()='NEW_DATE']='2025-02-14T00:00:00']")

二、获取列表中第一条<properties>内容

=IMPORTXML("https://home.treasury.gov/resource-center/data-chart-center/interest-rates/pages/xml?data=daily_treasury_yield_curve&field_tdr_date_value_month=202502", "(//*[local-name()='properties'])[1]")

三、获取列表中最后一条<properties>内容

=IMPORTXML("https://home.treasury.gov/resource-center/data-chart-center/interest-rates/pages/xml?data=daily_treasury_yield_curve&field_tdr_date_value_month=202502", "(//*[local-name()='properties'])[last()]")

补充:提取特定字段

如果需要从指定日期的<properties>中提取单个字段(比如10年期收益率),可以继续嵌套local-name()匹配字段名:

=IMPORTXML("https://home.treasury.gov/resource-center/data-chart-center/interest-rates/pages/xml?data=daily_treasury_yield_curve&field_tdr_date_value_month=202502", "//*[local-name()='properties' and *[local-name()='NEW_DATE']='2025-02-14T00:00:00']/*[local-name()='BC_10YEAR']")

内容的提问来源于stack exchange,提问作者G. Jonathan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 09:39:53