Mek
Mek

Reputation: 65

Html Agility - Get Value by Name Tag

I need to get a value from an input, but the id always change, only the name is the same. Didn't found anything on google to extract the value by the name tag.

Example:

<input type="hidden" name="data[_Token][key]" value="5aafaee2dd21555c2615fd26c0cccd0f1b2c3018" id="Token749368899" /></div>

I look forward to some answers.

Upvotes: 1

Views: 802

Answers (3)

L.B
L.B

Reputation: 116168

var input= doc.DocumentNode
              .Descendants("input")
              .First(n=>n.Attributes["name"].Value=="data[_Token][key]");

Upvotes: 3

Narendra
Narendra

Reputation: 3117

Try this

var dummy = document.getElementsByName("data[_Token][key]");

This will return you elements which has name "data[_Token][key]".

Upvotes: -1

Gregor Menih
Gregor Menih

Reputation: 5126

You can try getting the first part of Id, if it's always Token#####

//input[starts-with(@id, 'Token')]

Upvotes: 0

Related Questions