【问题标题】:Xpath - Get HTML element if its class contains some textXpath - 如果其类包含一些文本,则获取 HTML 元素
【发布时间】:2015-05-09 05:49:58
【问题描述】:

如果元素的类包含一些文本,我可以得到一个元素吗?

例子:

<div class="headerbody"></div>   - match (header)
<div class="headerbottom"></div>   - match (header)
<dov class="text"></div>     - not match (header)

【问题讨论】:

    标签: html xpath


    【解决方案1】:

    您可以在 XPath 谓词中使用 contains()。像这样:

    div[contains(@class, 'header')]
    

    【讨论】:

    • 同意。另外,如果您担心大小写问题,请先在 @class 上使用 translate(),如下所示: div[contains(translate(@class, 'ABCDEFG..Z', 'abcdefg..z'))]跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 2020-02-17
    • 1970-01-01
    • 2020-09-27
    • 2013-01-06
    • 1970-01-01
    相关资源
    最近更新 更多