2016-10-31 60 views
-4

<a class="product-name" href="http:xyz" title="Polac pineapple slices 3kg">Polac pineapple slices 3kg</a> <div class="price-box"> <span class="regular-price" id="product-price-5489"> <span class="price">Rs 665</span> </span>如果一個HTML標籤匹配,則另一標籤應使用htmlagilitypack

我想從跨度標籤得到的價格被抓取,但是匹配時,它應該提供特定項目的價格。就像如果一個標籤有內部文本Polac菠蘿那麼它應該返回665盧比以下 代碼是我使用

` 
var aTags = document.DocumentNode.SelectNodes("//a"); 
       var nextTags = document.DocumentNode.SelectNodes("//span"); 
if (aTags != null) 
       { 
        foreach (var aTag in aTags) 
        { 
         s += counter + ". " + aTag.InnerText + "<br>"; 
         //s += aTag.InnerText; 
         if (aTag.InnerText == "Polac pineapple") 
         { 
          brandcheck = true; 
          find += aTag.InnerText + " "; 

          foreach (var nextTag in nextTags) 
          { 
           //s += counter + ". " + nextTag.InnerText + "<br>"; 
           s += nextTag.InnerText; 
           if (nextTag.InnerText.Contains("Rs")) 
           { 
            brandcheck = true; 
            find = nextTag.InnerText + " "; 
           } 
          }` 
+0

你可以添加你的示例代碼 – ChrisBint

+0

@ChrisBint簽出,我已經添加了代碼! –

回答

0

你能更準確?

您可以使用「id」。

<span id="thisspan">A uniquely identifiable element.</span> 

id屬性爲文檔中的元素提供唯一標識符。它可以被一個元素用來創建一個到這個特定元素的超鏈接。

id屬性最重要的方面是它必須是絕對唯一的。與可能將相同值應用於頁面中的許多元素的class屬性不同,應用於元素的id不能與在同一頁面上任何其他位置使用的id匹配。

id屬性值必須以羅馬字母(a-z或A-Z)中的一個字母開頭;這可以跟隨字母(a-z或A-Z),數字(0-9),連字符( - ),下劃線(_),冒號(:)和句點(。)的任意組合。 id值是區分大小寫的,因此這是我和這是我將被視爲在同一個網頁上單獨和唯一可識別的元素。

+0

我很感謝你的回覆.. 實際上有多個相同id的span:/ like

相關問題