get p tags that come after a specific tag using htmlagilitypack

c# html-agility-pack web-crawler

Question

I'm crawling a website using htmlagilitypack c#:

i have in the source code of an html page

....
<p>this a p that come before h3</p>
....
....
<h3>this h3 </h3>

<p>first p after h3</p>

....

<p>seconde p after h3</p>

i want to to all get all Ps that come after

is there a way to use a where to filter Ps using position.

where (position(p)>position(h3))

Popular Answer

Try the following code:

var htmlText = "source code of your html page";
var htmlDoc.LoadHtml(htmlText);
var h3= htmlDoc.DocumentNode.SelectNodes("//h2");
var lineNum = h3[0].Line;
var p = htmlDoc.DocumentNode.SelectNodes("//p").Where(x => x.Line > lineNum);



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