【问题标题】:import.io selecting css class with xpath that contain certain value/characterimport.io 使用包含特定值/字符的 xpath 选择 css 类
【发布时间】:2015-01-19 17:29:16
【问题描述】:
<div id="mDetails">
<span class="textLabel">Bar Number:</span>
    <p class="profileText">YYYYYYYYYYYYYYYYYYYY</p>
<span class="textLabel">Address:</span>
    <p class="profileText">YYYYYYYYYYYYYYYYYYY<br>YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY<br>United States</p>
<span class="textLabel">Phone:</span>
    <p class="profileText">123465798</p>
<span class="textLabel">Fax:</span>
    <p class="profileText">987654321</p>
<span class="textLabel">Email:</span>
    <p class="profileText">regina@rbr3.com</p>
<span class="textLabel">County:</span>
    <p class="profileText">YYYYYYYYYYYYYYY</p>
<span class="textLabel">Circuit:</span>
    <p class="profileText">YYYYYYYYYY</p>
<span class="textLabel">Admitted:</span>
    <p class="profileText">00/00/0000</p>
<span class="textLabel">History:</span>
    <p class="profileText">YYYYYYYYYYYYYYYYY</p>

我只在我使用//*[@class="profileText"]它返回该类的所有内容时才尝试选择电子邮件,我只想在值中存在@时返回。

【问题讨论】:

    标签: xpath css-selectors import.io


    【解决方案1】:

    通过调整输入 XML 以将 &lt;br&gt; 更改为 &lt;br/&gt;(否则它不是有效的 XML),以下 XPath 将选择所有具有类 profileText 并包含 @p 元素:

    //p[@class='profileText'][contains(.,'@')]
    

    返回

    <p class="profileText">regina@rbr3.com</p>
    

    如果只想获取值,可以使用string()

    string(//p[@class='profileText'][contains(.,'@')])
    

    返回

    regina@rbr3.com
    

    请注意,string() 只会返回第一个匹配项的值,而返回 p 元素的第一个 XPath 会返回所有匹配项。

    【讨论】:

      猜你喜欢
      • 2021-12-01
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 2012-02-07
      • 2021-12-13
      • 2012-01-27
      • 1970-01-01
      相关资源
      最近更新 更多