AAP AAP - 1 year ago 102
C# Question

HTMLAgilityPack How to parse a specific attribute in HTML Contents

Can anyone please help me how to parse a specific attribute (if I understand right). the below is a sample.

<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">

I would like to parse where value = "778768" from the above html data.
Please advice. Many thanks.

Answer Source

You could do something like this.

  var val = doc
              .SelectSingleNode("//input[@type='hidden' and @name='ContentObjectID']")

Check this fiddle demo

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download