zoukankan      html  css  js  c++  java
  • xpath的一些常用使用

    xml文档
    <html>
    <head>
    <title>My page</title>
    </head>
    <body>
    <h2>Welcome to my <a href="#" src="x">page</a></h2>
    <p>This is the first paragraph.</p>
    <p class="test">
    编程语言<a href="#">python</a>
    <img src="#" alt="test"/>javascript
    <a href="#"><strong>C#</strong>JAVA</a>
    </p>
    <p class="content-a">a</p>
    <p class="content-b">b</p>
    <p class="content-c">c</p>
    <p class="content-d">d</p>
    <p class="econtent-e">e</p>
    <p class="heh">f</p>
    <!-- this is the end -->
    </body>
    </html>


    常用函数

    starts-with();以什么开头 //p[starts-with(@class,'content')]/text() --> a,b,c,d
    contains();包含什么字段 //p[contains(@class,'content')]/text() -->a,b,c,d,e
    last();最后一个 //p[last()]/text() --> f
    last()-1;倒数第二个,以此类推 //p[last()-1]/text() -->e
    position();返回元素位置 //p[position() = 1] --> This is the first paragraph.
    text();获取文本
    string();获取元素下所有文本 xpath('string(//p[@class="test"])')
    '编程语言python javascript C#JAVA'
    not();与条件相反 //p[not(@class='test')]

    常用方法

    //p[a] 包含a元素的p元素
    //p[text() = 'f'] 元素文本值为f的p元素
    //p[a or @class='heh'] 包含a元素或者@class值为heh的p元素
    //p[a and img] 同时包含a和img标签的p元素

  • 相关阅读:
    python 2
    Python 1 practice
    python 1
    Python多线程_笔记
    背景自适应不会随浏览器界面放大速效而改变
    平行四边形定理
    动态规划3(区间+树形)
    素数快速生成
    设CPU共有16根地址线,8根数据线,,,
    贪心+huffman编码+模拟退火+分治
  • 原文地址:https://www.cnblogs.com/snow-l/p/9548384.html
Copyright © 2011-2022 走看看