特殊标签

找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

最新文章

  1. 【.NET深呼吸】Zip文件操作(1):创建和读取zip文档
  2. ExpressJs server中Router的设置
  3. 配置Supervisor开机启动
  4. ubuntu14.04 wifi驱动安装
  5. 洛谷P2085 最小函数值(minval)
  6. [HZNUOJ1524]排队买票(DP)
  7. oc-09-#pragma mark指令的使用,用于查找代码
  8. aop动态代理学习
  9. 老李分享:接电话扩展之uiautomator 2
  10. [图形学] Chp17 OpenGL光照和表面绘制函数
  11. ASP.NET Core 运行原理剖析
  12. bzoj:1700: [Usaco2007 Jan]Problem Solving 解题
  13. springboot缓存注解——@Cacheable
  14. 一个AI产品经理怎么看AI的发展
  15. java ==、equals、hashcode有什么区别
  16. Cassandra.yaml 配置详解
  17. 集合之ArrayList
  18. 【bzoj2806】 Ctsc2012—Cheat
  19. IIS安装出现“安装程序无法复制文件CONVLOG.EX_”的解决办法
  20. Treflection05_扩展习题

热门文章

  1. EF 将MSSQL 更换成 POSTRESQL
  2. Java并发与多线程
  3. conda创建和使用python的虚拟环境
  4. 并发编程:生产消费模型、死锁与Rlock、线程、守护线程、信号量、锁
  5. ProgressDialog 进度条的初步认识
  6. 检测udp端口
  7. phpMyAdmin出现Fatal error: Maximum execution time of 300 seconds
  8. Linux之checkconfig 服务自启动
  9. Liux chmod 给文件夹赋权限
  10. top命令经常用来监控linux的系统状况,比如cpu、内存的使用,程序员基本都知道这个命令。 按 q 退出