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

如何通过XPath定位d属性非零的SVG path元素

正确XPath实现方案

  1. 若需求为排除d属性完全等于M0 0的path元素,直接使用不等于判断即可:
//div[@id="map"]//div[contains(@class,"map")]//div[@class="leaflet-pane"]//div[@class="leaflet-pane2"]//*[name()='svg']//*[name()='path' and @d!="M0 0"]
  1. 若需求为筛选d属性完全不包含0字符的path元素,使用not+contains组合逻辑,注意contains函数的参数顺序为contains(目标属性, 待匹配内容):
//div[@id="map"]//div[contains(@class,"map")]//div[@class="leaflet-pane"]//div[@class="leaflet-pane2"]//*[name()='svg']//*[name()='path' and not(contains(@d, "0"))]
  1. 若需求为筛选d属性包含特定内容(比如你示例中的125)的path元素,写法如下:
//*[name()='svg']//*[name()='path' and contains(@d,"125")]

错误原因说明

你之前编写的XPath运行失败是因为contains函数的调用格式错误,不能将属性放在函数外,需要把要检查的属性作为第一个参数传入函数内。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 05:57:03