新手xpath查询

时间:2017-02-02 10:12:40

标签: xml xpath

我尝试将xpath查询到包含以下行的文件:

<div id="pPrice">
<b>Preis</b>
<br/>
<div class="price" style="margin-top:2px">
    <nobr>
        <span class="price_info">Jetzt 48% sparen!</span>
        <br/>
        <span class="price_info">
            Statt 
            <strike>30,60 €</strike>
            <strong> nur</strong>
        </span>
        <strong>
            <span class="productSpecialPrice">15,90 €</span>
        </strong>
    </nobr>
</div>

当我想要越过&#39;价格(价值是30,60),我使用以下,它工作正常:

.//*[@id='pPrice']/div[1]/nobr/span[2]/strike

现在我想得到productSpecialPrice(价值是15,90€),我尝试了这个:

.//*[@id='pPrice']/div[1]/nobr/strong/span

但它不起作用。我该如何编辑?

谢谢!

UPD:现在一切正常,但在这种情况下:

<div id="pPrice">
<b>Preis</b>
<br/>
<div class="price" style="margin-top:2px">
<nobr>
<span class="price_info">Jetzt 33% sparen!</span>
<br/>
<span class="price_info">
Statt 
<strike>41,70 €</strike>
<strong> nur</strong>
</span>
<strong>
<span class="productSpecialPrice">27,90 €</span>
</strong>
</nobr>
</div>
<div class="priceinfo">
inkl. gesetzl. MwSt zzgl. 
<a class="priceinfolink" href="javascript:openShipping();">Versandkosten</a>
</div>
</div>
<div id="pAvailability">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
</div>
<div id="pPrice">
<b>Preis für 2. Wahl Spiel</b>
<small>
<a href="JavaScript:var win=open('/zweitewahl.html', '', 'scrollbars=no,location=0,left=300, top = 100,toolbar=0,status=0,resize=0,width=400,height=310')">
</small>
<br/>
<div class="price" style="margin-top:2px">
<nobr>
<nobr>36,00 €</nobr>
</div>
<div class="priceinfo">
inkl. gesetzl. MwSt zzgl. 
<a class="priceinfolink" href="javascript:openShipping();">Versandkosten</a>
</div>

查询返回两个值:&#39; 27,9€&#39;和&#39; 36€&#39;如何在查询中指定我需要&#39; 27,9€&#39;值?

1 个答案:

答案 0 :(得分:0)

您可以尝试使用以下内容:

.//div[@id='pPrice'][b[text()="Preis"]]//span[@class="productSpecialPrice"]