如何在此处使用 XPath contains()? [英] How to use XPath contains() here?

查看:36
本文介绍了如何在此处使用 XPath contains()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 XPath.我查看了此处的其他 contains() 示例,但没有使用 AND 运算符.我无法让它工作:

//ul[@class='featureList' and contains(li, 'Model')]

开启:

<预><代码>...<ul class="featureList"><li><b>类型:</b>夹扇</li><li><b>特点:</b>空气移动:65 英尺.安培:1.1夹子:夹住最大 1.63" 的任何表面插头:重型型号上的 3 脚接地插头用途:车库、车间、宿舍、健身室、甲板、办公室和</li><li><b>速度设置:</b>2种速度</li><li><b>颜色:</b>黑色</li><li><b>功耗:</b>62W/li>
  • 高度:14.5"</li><li><b>宽度:</b>烤架直径:9.5"</li><li><b>长度:</b>11.5"
  • <li><b>型号:</b>CR1-0081-06</li><li><b>项目编号:</b>N82E16896817007</li><li><b>退货政策:</b></li>...

    解决方案

    您只查看查询中的第一个 li 子项,而不是查找任何 li> 可能包含文本的子元素,'Model'.您需要的是如下查询:

    //ul[@class='featureList' 和 ./li[contains(.,'Model')]]

    此查询将向您提供具有 featureListclass 和一个或多个 li 子元素的元素,这些子元素包含文本 '模型'.

    I'm trying to learn XPath. I looked at the other contains() examples around here, but nothing that uses an AND operator. I can't get this to work:

    //ul[@class='featureList' and contains(li, 'Model')]
    

    On:

    ...
    <ul class="featureList">
    
    <li><b>Type:</b> Clip Fan</li><li><b>Feature:</b> Air Moved: 65 ft.
        Amps: 1.1
        Clip: Grips any surface up to 1.63"
        Plug: 3 prong grounded plug on heavy duty model
        Usage: Garage, Workshop, Dorm, Work-out room, Deck, Office & more.</li><li><b>Speed Setting:</b> 2 speeds</li><li><b>Color:</b> Black</li><li><b>Power Consumption:</b> 62 W</li><li><b>Height:</b> 14.5"</li><li><b>Width:</b> Grill Diameter: 9.5"</li><li><b>Length:</b> 11.5"</li>
    
    <li><b>Model #: </b>CR1-0081-06</li>
    <li><b>Item #: </b>N82E16896817007</li>
    <li><b>Return Policy: </b></li>
    </ul>
    ...
    

    解决方案

    You are only looking at the first li child in the query you have instead of looking for any li child element that may contain the text, 'Model'. What you need is a query like the following:

    //ul[@class='featureList' and ./li[contains(.,'Model')]]
    

    This query will give you the elements that have a class of featureList with one or more li children that contain the text, 'Model'.

    这篇关于如何在此处使用 XPath contains()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆