如何 select 从某个数字开始的所有 h 标签(XPath)?
How to select all h tags starting from a certain number (XPath)?
我想 select 所有 h
标签开始,例如,从标签 h3
开始,即 h3
、h4
、h5
...我只知道如何 select h3
:
//h:h3
使用这个:
//*[matches(name(), '^h\d')]
如果元素名称中有命名空间则使用:
//*[matches(local-name(), '^h\d')]
XPath 1.0
保持简单并列举它们:
//*[self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]
XPath 2.0
您可以通过多种方式使用正则表达式。例如...
所有格式为 h
number:
的标签
//*[matches(local-name(),'^h\d+$')]
对于单个数字的有限范围:
//*[matches(local-name(),'^h[3-6]$')]
我想 select 所有 h
标签开始,例如,从标签 h3
开始,即 h3
、h4
、h5
...我只知道如何 select h3
:
//h:h3
使用这个:
//*[matches(name(), '^h\d')]
如果元素名称中有命名空间则使用:
//*[matches(local-name(), '^h\d')]
XPath 1.0
保持简单并列举它们:
//*[self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]
XPath 2.0
您可以通过多种方式使用正则表达式。例如...
所有格式为 h
number:
//*[matches(local-name(),'^h\d+$')]
对于单个数字的有限范围:
//*[matches(local-name(),'^h[3-6]$')]