Html Agility Pack: how to parse a webresponse and get a specified html element in c#

c# html html-agility-pack parsing

Question

I googled my problem and found Html Agility Pack to parse html in c#. But there is no good examples and I can't use it to my purpose. I have a html document and it has a part like this:

<div class="pray-times-holder">
    <div class="pray-time">
        <div class="labels">
            Time1:</div>
        04:28:24
    </div>
    <div class="pray-time">
        <div class="labels">
            Time2:</div>
        06:04:41
    </div>
</div>

I want to get the value for Time1 and Time2. e.g. Time1 has value 04:28:24 and Time2 has value 06:04:41 and I want to get these values. Can you help me please?

Popular Answer

This console application code:

 HtmlDocument doc = new HtmlDocument();
 doc.Load(yourHtml);
 foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//div[@class = 'labels']"))
 {
     Console.WriteLine(node.NextSibling.InnerText.Trim());
 }

will output this:

04:28:24
06:04:41



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