使用 html 敏捷获取此节点的值
using html agility to get the value of this node
正在尝试使用html agility pack 获取此处的份数值
<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。
SelectSingleNode("//span[@ng-bind='adjustedServings']").InnerText
应该可以解决问题。如果您有多个这样的 span
,请改用 SelectNodes
,在 foreach
中使用它并分别访问节点上的 InnerText
。
没有尝试编译,如果你运行出错,我会编辑它
正在尝试使用html agility pack 获取此处的份数值
<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。
SelectSingleNode("//span[@ng-bind='adjustedServings']").InnerText
应该可以解决问题。如果您有多个这样的 span
,请改用 SelectNodes
,在 foreach
中使用它并分别访问节点上的 InnerText
。
没有尝试编译,如果你运行出错,我会编辑它