Xpath语法相对比较简单重要的是进行识记。1./html//textarea 双斜杠跨结点定位2.//button[idchat-submit-button] 加大括号和写入id信息 找到id名称为chat-submit-button的所有button标签3.//button[text()百度一下] 根据文本定位 找到文本内容为百度一下的button标签4./html/body//div/span[*] 代表所有拥有属性的span标签5./html/body//div/*代表选中div下的所有标签6.//*[ids-top-left]/a[last()-3] 所有id为指定内容的标签它们中的a标签最后一个位置-3个位置7.//*[ids-top-left]/a[position()4] 选中位置大于4的标签8.//*[ids-top-left]/a/.. 选中当前节点的父节点9.//ul[classs-hotsearch-content]/li/a[span div 2 1 ]选中a标签其中它的span标签的文本内容除2等于110.//ul[classs-hotsearch-content]/li/a[span mod 21and span6]选中a标签其中span文本内容取余2等于1并且大于611.//ul[classs-hotsearch-content]/li/a[span mod 21or span6]选中a标签其中span文本内容取余2等于1或者大于612.//ul[not(classs-hotsearch-content)]/li/a[span mod 21or span6]表示选中不是该属性的标签13.//ul[classs-hotsearch-content]/li/a[span mod 21or not(span6)]反选span在1到五和1、3、5、7这些全部选中not加括号再加条件14. //ul[classs-hotsearch-content]/li[1]|//ul[classs-hotsearch-content]/li[2]表示选中两个表达式的并集 用 | 连接。函数contains15.//ul[contains(class,hotsearch)]ul contains函数括号中放两个参数 1.属性名 2.模糊匹配不变的字符text16.//ul[contains(class,hotsearch)]/li/a/span[contains(text(),华为)]文本匹配提取标签中文本包含华为的span标签轴17.//ul[contains(class,hotsearch)]/li/span/preceding-sibling::a选取当前节点span标签之前的所有同级节点标签。18.//ul[contains(class,hotsearch)]/li/child::span选取当前节点li下的所有子节点的span标签。19.//ul[contains(class,hotsearch)]/li/a/parent::li选取当前节点a标签中的所有父节点的li标签更多的一些轴20.函数多条件//ul[classs-hotsearch-content]/li[contains(class,hotsearch-item even) and contains(data-index,5)] 选中li标签 class属性包含hotsearch-item even并且data-index属性包含5的元素//input[typetext and nameuser] 选中属性type值为text且属性name值为user的元素//*[starts-with(href,https)] 选中属性href开头为http的元素//*[contains(., 搜索)]选择包含搜索文本的元素 大范围查找
Xpath语法
Xpath语法相对比较简单重要的是进行识记。1./html//textarea 双斜杠跨结点定位2.//button[idchat-submit-button] 加大括号和写入id信息 找到id名称为chat-submit-button的所有button标签3.//button[text()百度一下] 根据文本定位 找到文本内容为百度一下的button标签4./html/body//div/span[*] 代表所有拥有属性的span标签5./html/body//div/*代表选中div下的所有标签6.//*[ids-top-left]/a[last()-3] 所有id为指定内容的标签它们中的a标签最后一个位置-3个位置7.//*[ids-top-left]/a[position()4] 选中位置大于4的标签8.//*[ids-top-left]/a/.. 选中当前节点的父节点9.//ul[classs-hotsearch-content]/li/a[span div 2 1 ]选中a标签其中它的span标签的文本内容除2等于110.//ul[classs-hotsearch-content]/li/a[span mod 21and span6]选中a标签其中span文本内容取余2等于1并且大于611.//ul[classs-hotsearch-content]/li/a[span mod 21or span6]选中a标签其中span文本内容取余2等于1或者大于612.//ul[not(classs-hotsearch-content)]/li/a[span mod 21or span6]表示选中不是该属性的标签13.//ul[classs-hotsearch-content]/li/a[span mod 21or not(span6)]反选span在1到五和1、3、5、7这些全部选中not加括号再加条件14. //ul[classs-hotsearch-content]/li[1]|//ul[classs-hotsearch-content]/li[2]表示选中两个表达式的并集 用 | 连接。函数contains15.//ul[contains(class,hotsearch)]ul contains函数括号中放两个参数 1.属性名 2.模糊匹配不变的字符text16.//ul[contains(class,hotsearch)]/li/a/span[contains(text(),华为)]文本匹配提取标签中文本包含华为的span标签轴17.//ul[contains(class,hotsearch)]/li/span/preceding-sibling::a选取当前节点span标签之前的所有同级节点标签。18.//ul[contains(class,hotsearch)]/li/child::span选取当前节点li下的所有子节点的span标签。19.//ul[contains(class,hotsearch)]/li/a/parent::li选取当前节点a标签中的所有父节点的li标签更多的一些轴20.函数多条件//ul[classs-hotsearch-content]/li[contains(class,hotsearch-item even) and contains(data-index,5)] 选中li标签 class属性包含hotsearch-item even并且data-index属性包含5的元素//input[typetext and nameuser] 选中属性type值为text且属性name值为user的元素//*[starts-with(href,https)] 选中属性href开头为http的元素//*[contains(., 搜索)]选择包含搜索文本的元素 大范围查找