How to parse a webresponse and obtain a specific html element in C# using the Html Agility Pack

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?

1
1
4/30/2012 5:07:26 AM

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
1
5/3/2012 7:10:54 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow