XPATH了解
特殊标签
找SVG这种特殊标签可以使用[name()='svg'],如//[name()='svg']/[name()='line'][2]
文本
找标签内的文本时可以使用: //*[text()='abc']
如果有空格或回车什么的,就截空下://a[normalize-space(text())='abc']
如果想取回当前节点下的所有文本可用://a[normalize-space(.)]
常用函数
函数名 | 解释 |
---|---|
contains(@class,'btn') | class属性包含btn |
starts-with(@class,'btn') | class属性以btn开头 |
ends-with(@class,'btn') | class属性以btn结尾 |
text() | 文本 |
//input[@type='a'][@name='b'] | 并且 |
//input[@type='a' and @name='b'] | 并且 |
//input[@type='a' or @name='b'] | 或 |
//input[@*='a'] | 匹配所有属性 |
//a[last()] | a的最后一个子元素 |
boolean()
ceiling()
choose()
concat()
contains()
count()
current() XSLT-specific
document() XSLT-specific
element-available()
false()
floor()
format-number() XSLT-specific
function-available()
generate-id() XSLT-specific
id() (partially supported)
key() XSLT-specific
lang()
last()
local-name()
name()
namespace-uri()
normalize-space()
not()
number()
position()
round()
starts-with()
string()
string-length()
substring()
substring-after()
substring-before()
sum()
system-property() XSLT-specific
translate()
true()
unparsed-entity-url() XSLT-specific (not supported)
轴 descendant
XPath轴(XPath Axes)可定义某个相对于当前节点的节点集:
语法:
轴名称::节点测试[谓语]
轴 | 选取值 |
---|---|
child | 选取当前节点的所有子元素 |
parent | 选取当前节点的父节点 |
descendant | 选取当前节点的所有后代元素(子、孙等) |
ancestor | 选取当前节点的所有先辈(父、祖父等) |
descendant-or-self | 选取当前节点的所有后代元素(子、孙等)以及当前节点本身 |
ancestor-or-self | 选取当前节点的所有先辈(父、祖父等)以及当前节点本身 |
preceding-sibling | 选取当前节点之前的所有同级节点 |
following-sibling | 选取当前节点之后的所有同级节点 |
preceding | 选取文档中当前节点的开始标签之前的所有节点 |
following | 选取文档中当前节点的结束标签之后的所有节点 |
self | 选取当前节点 |
attribute | 选取当前节点的所有属性 |
namespace | 选取当前节点的所有命名空间节点 |
Refer to
https://developer.mozilla.org/en-US/docs/Web/XPath/Functions
https://www.cnblogs.com/jpfss/p/10973806.html
https://www.cnblogs.com/zhaozhan/archive/2009/09/10/1563728.html
http://www.zvon.org/xxl/XPathTutorial/General_chi/examples.html
最新文章
- 【.NET深呼吸】Zip文件操作(1):创建和读取zip文档
- ExpressJs server中Router的设置
- 配置Supervisor开机启动
- ubuntu14.04 wifi驱动安装
- 洛谷P2085 最小函数值(minval)
- [HZNUOJ1524]排队买票(DP)
- oc-09-#pragma mark指令的使用,用于查找代码
- aop动态代理学习
- 老李分享:接电话扩展之uiautomator 2
- [图形学] Chp17 OpenGL光照和表面绘制函数
- ASP.NET Core 运行原理剖析
- bzoj:1700: [Usaco2007 Jan]Problem Solving 解题
- springboot缓存注解——@Cacheable
- 一个AI产品经理怎么看AI的发展
- java ==、equals、hashcode有什么区别
- Cassandra.yaml 配置详解
- 集合之ArrayList
- 【bzoj2806】 Ctsc2012—Cheat
- IIS安装出现“安装程序无法复制文件CONVLOG.EX_”的解决办法
- Treflection05_扩展习题