简体   繁体   English

如何使用C#HtmlAgilityPack解析HTML表单中的输入类型

[英]How to Parse an input type in HTML form using C# HtmlAgilityPack

I have these HTML form in which am trying to get the input value 我有这些HTML表单,试图获取输入值

<form action="/checkout/cart" method="POST" class="update-qty-form">
    <div class="quantity num-selector">
        <input type="tel" value="1" name="qty" maxlength="3" class="quantity-increment">
    </div>
</form>

With the Code it doesn't work 使用该代码不起作用

var Quantity = items
    .Elements("form").First()
    .Elements("div").First()
    .Elements("input").First().Attributes["value"].Value;
Debug.WriteLine("The Quantity is : " + Quantity);

We recently used this bit of code to extract data from an attribute: 我们最近使用以下代码从属性中提取数据:

var htmlDoc = new HtmlDocument();
 htmlDoc.LoadHtml(@"<form action='/checkout/cart' method='POST' class='update-qty-form'><div class='quantity num-selector'><input type='tel' value='1' name='qty' maxlength='3' class='quantity-increment'></div></form>");


var value = htmlDoc.DocumentNode.SelectSingleNode("//input").Attributes["value"].Value;

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM