Unable to extract all paragraph tags from HTML document using Html Agility Pack

48 Views Asked by At

I am trying to get all <p></p> from an HTML document using Html Agility Pack. However, when I try below, all the nodes are null.

var doc = new HtmlDocument();
doc.Load(@"c:\Webs\test.html");
var nodes = doc.DocumentNode.SelectNodes("//p");

foreach ( var paragraph in nodes ) { 
    Console.WriteLine($"paragraph {paragraph.InnerText}");
}

Html

    <!DOCTYPE html>

<html>
<head>
</head>
<body>
     <p>I am a paragraph</p>
     <p>I am a paragraph</p>
     <h1>I am an H1</h1>
     <p>I am a paragraph</p>
     <p>I am a paragraph</p>
     <p>I am a paragraph</p>
     <h1>I am an H1</h1> 
</body>
</html>
0

There are 0 best solutions below