任何人都可以帮我解析一下如何解析一个特定的属性(如果我理解的话)。以下是一个样本。
<div class="buy-container">
<form action="/content/action" method="post">
<button class="product-buy">buy</button>
<input type="hidden" name="ActionAddToBasket">
<input type="hidden" value="198300" name="ContentNodeID">
<input type="hidden" value="778768" name="ContentObjectID">
<input type="hidden" value="full" name="ViewMode">
</form>
</div>
&#13;
答案 0 :(得分:1)
你可以这样做。
var val = doc
.DocumentNode
.SelectSingleNode("//input[@type='hidden' and @name='ContentObjectID']")
.Attributes["value"].Value;
选中此fiddle demo
答案 1 :(得分:0)
试试这个:
var html = @"
<div class=""buy-container"">
<form action=""/content/action"" method=""post"">
<button class=""product-buy"">buy</button>
<input type=""hidden"" name=""ActionAddToBasket"">
<input type=""hidden"" value=""198300"" name=""ContentNodeID"">
<input type=""hidden"" value=""778768"" name=""ContentObjectID"">
<input type=""hidden"" value=""full"" name=""ViewMode"">
</form>
</div>
";
var doc = new HtmlDocument();
doc.LoadHtml(html);
var input = doc.DocumentNode.SelectSingleNode("//input[@name = 'ContentObjectID']");
// your desired value
var val = input.GetAttributeValue("value", "");