我正在使用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>
我希望所有人都能得到所有后来的P ..
有没有办法使用位置过滤Ps的位置。
其中(位置(p)>位置(h3))
请尝试以下代码:
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);