2017-06-11 30 views
0

嘗試使用HTML敏捷包拿到份量這裏數的值使用HTML的靈活性得到這個節點的值

<span class="recipe-ingredients__header__toggles"> 
    <span class="ready-in-time__container"> 
     <span class="ready-in-time">3 h 30 m</span> 
     <span class="icon--stats-clock"></span> 
    </span> 

<meta id="metaRecipeServings" itemprop="recipeYield" content="8"> 

<a href="" id="servings-button" popup-trigger="servingsSection"> 
    <span class="servings-count" ng-class="{'active': servingsSection_showing}"><span ng-bind="adjustedServings" class="ng-binding">8</span><span class="servings-count__desc" ng-class="{'active': servingsSection_showing}"> servings</span></span> 

    <span class="icon--adjust-servings" ng-class="{'active': servingsSection_showing}"></span> 
</a> 

    <a href="" id="nutrition-button" popup-trigger="nutritionSection"> 
     <span class="calorie-count" ng-class="{'active': nutritionSection_showing}"><span>562</span> <span class="calorie-count__desc" ng-class="{'active': nutritionSection_showing}"> cals</span></span> 
     <span class="icon--nutrition-info" ng-class="{'active': nutritionSection_showing}"></span> 
    </a> 

具體來說,我正在看標籤

<span ng-bind="adjustedServings"> 

具有值「8」。我在這裏已經得到了其他所有的價值,但似乎無法解決這個問題。我只是想在這種情況下的整數8。

回答

1
SelectSingleNode("//span[@ng-bind='adjustedServings']").InnerText 

應該這樣做。如果您有多個span,請使用SelectNodes,請將其用於foreach,並分別在節點上訪問InnerText

沒有嘗試編譯,如果你遇到的錯誤,我將修改它

+0

這也得到了節點,但始終內部文本始終是==「」出於某種原因。 –

+1

奇怪的是...... '總是包含相同的數字或者這只是一個巧合。你可以從中得到數字,因爲它可能更可能是一個屬性。另外:您是否在調試器中檢查了節點? InnerText屬性在那裏是一樣的嗎?或者您嘗試將InnerText屬性設置爲其他內容,再次讀取它並檢查它是否可能是節點本身的問題。 – Kartoffel