import.io选择包含特定值/字符的xpath的css类

时间:2015-01-19 17:29:16

标签: xpath css-selectors import.io

<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"]它的可用原因,它会返回此类的所有内容,我只想在值{。}}出现时返回。

1 个答案:

答案 0 :(得分:3)

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

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

返回

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

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

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

返回

regina@rbr3.com

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