-
- 路径查找
//:子孙节点,不考虑层级
/:找直接子节点
- 路径查找
-
- 谓词查询
//div【@id="content"】
- 谓词查询
-
- 属性查询
//@class
- 属性查询
-
- 模糊查询
//div[contains(@id,"he")]
//div[starts-with(@id, "he")]
- 模糊查询
-
- 内容查询
//div/h1/text()
- 内容查询
-
- 逻辑查询
//div[@id="head" and @class="s_down"]
//text | //price
- 逻辑查询
-
- 节点轴选择
-
ancestor轴获取所有祖先节点
result = html.xpath('//li[1]/ancestor:😗')
result = html.xpath('//li[1]/ancestor::div') -
attribute获取所有属性值
result = html.xpath('//li[1]/attribute:😗') -
child轴获取直接子节点
result = html.xpath('//li[1]/child::a[@href="link1.html"]') -
descendant轴获取所有子孙节点
result = html.xpath('//li[1]/descendant::span') -
following轴获取当前节点之后所有节点
result = html.xpath('//li[1]/following:😗[2]') -
following—sibling轴获取当前节点后的同级节点
result = html.xpath('//li[1]/following-sibling:😗') -
- 获取子标签的所有文本
.xpath('normalize-space(string())')
内容查找
//a[normalize-space(text())='货运表现']
- 获取子标签的所有文本
-
- 不要携带某个标签
ul[not(@style="display: none;")]
- 不要携带某个标签
浙公网安备 33010602011771号