How can I get a specific attribute value?

.net c# html-agility-pack selectsinglenode

Question

There is an input element as below:

<input type="hidden" value="908" name="a">

I want to return 908 value using DocumentNode.SelectSingleNode. How can I do this?
The code below does not work?

string a = htmlDoc.DocumentNode.SelectSingleNode("//input[@name='a']").GetAttributeValue("value", true).ToString();

Accepted Answer

You're calling the wrong overload for GetAttributeValue(). Try using a string as the second parameter instead of a boolean:

string a = htmlDoc.DocumentNode.SelectSingleNode("//input[@name='a']").GetAttributeValue("value", "default");


Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why