Htmlagilitypack
使用次のコードを使用して、1つのタグの属性値を取得できます。
public string parseinput(HtmlDocument HtmlDocument)
{
try
{
return HtmlDocument.DocumentNode.SelectSingleNode("//input[@type=""text""]").Attributes["value"].Value;
}
catch (Exception ex)
{
string x= ex.ToString();
return "Error is... '"+x+"'" ;
}
}
最初の値を取得すると、実行を停止してその値を返しますが、すべてのテキスト型の値を出力として取得する必要があります。
これのために私は何をする必要がありますか?
あなたが必要とするSelectNodes
の代わりSelectSingleNode
return String.Join(",", HtmlDocument.DocumentNode.SelectNodes("//input[@type=""text""]")
.Select(n=>n.Attributes["value"].Value)
入力タイプと値の両方が必要な場合
var inputs = doc.DocumentNode.SelectNodes("//input").Select(n => new {
Type = n.Attributes["type"].Value, Value = n.Attributes["value"].Value }).ToList();