MarkLomme
MarkLomme

Reputation: 3

HTMLAgilityPack C#, How to extract text from nested Tags in DIV

I have this HTML code where I want to extract the date from:

<div id="footer">
    <div style="font-size:smaller">
        Added in:
        <strong>
            07/06/2021 2:15:36 PM
        </strong>
    </div>
</div>

This is my C# HTMLAgilityPack

doc.DocumentNode.SelectSingleNode("//div[@id='footer']").InnerText

Upvotes: 0

Views: 86

Answers (1)

Nima Talebi
Nima Talebi

Reputation: 874

doc.DocumentNode.SelectSingleNode("//div[@id='footer']/div/strong").InnerText

Update :

All Code :

        var html ="<div id=\"footer\"><div style=\"font-size:smaller\"> Added in:<strong> 07/06/2021 2:15:36 PM </strong></div></div>";
        var doc = new HtmlDocument();
        doc.LoadHtml(html);
        var time = doc.DocumentNode.SelectSingleNode("//div[@id='footer']/div/strong").InnerText;

and I extracted the Date

enter image description here

Upvotes: 1

Related Questions