How To Select By Attribute Within Perticular section/div through htmlagilitypack

663 views Asked by At

So I m using Htmlagilitypack on server side to parse html in C#. Here's a Question.. i have 2 div elements

<div>
<a data-clear="movies-something"></a>
<p data-clear="movies-something"></p>
</div>

<div>
<a data-clear="music-something"></a>
<p data-clear="music-something"></p>
</div>

i am looping through the div elements and want to find specific data-clear attributes for that. problem is when i am selecting nodes using

var cols = fdm.SelectNodes("//@data-clear");

on second case i am finding 4 instead of 2 columns..

how to select within only currently looping through div

1

There are 1 answers

5
MikkaRin On

Change your XPATH expression on follows

var cols = fdm.SelectNodes("//div[1]//@data-clear");