要选择的XPath语法

时间:2015-04-24 14:08:42

标签: xpath

我想只选择以下html中的标题:

<div class="urun">
    <div class="urun_resmi">
        <a class="urun_resmi_2703" href="/4riders-4-mevsim-ceket-siyah-sari-pmu2703" title="4RIDERS 4 MEVSİM CEKET SİYAH/SARI">
            <img src="http://WWW.MOTOMAXONLINESHOP.COM/pictures/200X-201431512318_20140313005.jpg" width="200" height="200" alt="4RIDERS 4 MEVSİM CEKET SİYAH/SARI" />
        </a>
    </div>
    <div class="urun_ismi">
        <a class="urun_ismi_2703" href="/4riders-4-mevsim-ceket-siyah-sari-pmu2703" title="4RIDERS 4 MEVSİM CEKET SİYAH/SARI">4RIDERS 4 MEVSİM CEKET SİYAH/SARI</a>
    </div>
    <div class="urun_kdvdahil_fiyati">
        <span>KDV Dahil 269,90&nbsp;TL</span>
    </div>
    <div class="urun_ikonlar">
        <a href="/4riders-4-mevsim-ceket-siyah-sari-pmu2703" title="Kampanyalı Ürün">
            <img class="kampanyali_urun_ikon" src="http://WWW.MOTOMAXONLINESHOP.COM/skin/1011/images/kampanyali.gif" alt="Kampanyalı Ürün" title="Kampanyalı Ürün" />
        </a>
    </div>
    <div class="urun_butonlar"></div>
</div>
</div>

我的代码是:

var nodes = doc.DocumentNode.SelectNodes((String.Format(@"//div[@class='urun']")));

但我只需要“4RIDERS4MEVSİMCEKETSİYAH/ SARI”

1 个答案:

答案 0 :(得分:0)

一个可能的xpath 假设您希望(已经确认)从title中获取<div class="urun_resmi">属性:

//div[@class='urun']/div[@class='urun_resmi']/a/@title

但是,Html Agility Pack的SelectNodes()只能返回节点而非属性,因此您可能需要在{{{}处结束xpath 1}}并继续以另一种方式选择/a属性:

title