如何使用Xpath提取特定的元素?

时间:2022-11-28 20:39:24

There is a list:

有一个清单:

<ul class="params">
     <li> <span>Brand:</span> Casio </li>                  
     <li> <span>Gender:</span> male </li>           
     <li> <span>Material:</span> metal </li>
</ul>

I am trying to extract specific "Gender" parameter. So I want to extract <li> element that has this information:

我正在尝试提取特定的“性别”参数。所以我想提取具有此信息的

  • 元素:

  • <span>Gender:</span> male 
    

    This is how I am trying to do it:

    这就是我试图这样做的方式:

    //ul[@class="params"]/li[text()[contains(.,'Gender')]] 
    

    Not working.

    How to extract this specific <li> element?

    如何提取这个特定的

  • 元素?

  • 1 个解决方案

    #1


    The "Gender:" is a child of span, not li:

    “性别:”是跨度的孩子,而不是李:

     //ul[@class="params"]/li[span="Gender:"]
    

    #1


    The "Gender:" is a child of span, not li:

    “性别:”是跨度的孩子,而不是李:

     //ul[@class="params"]/li[span="Gender:"]