Search code examples
c#html-agility-pack

How To Get Div inside Div htmlagilitypack


first .. sorry about my bad english

my question is how can i scrape div inside div in htmlagilitypack c#

this is test html code

<html>
  <div class="all_ads">

    <div class="ads__item">
       <div class="test">
          test 1
         </div>
     </div>

    <div class="ads__item">
       <div class="test">
          test 2
         </div>
     </div>

    <div class="ads__item">
       <div class="test">
          test 3
         </div>
     </div>

  </div>
</html>

how to make a loop that get all ads then loop that control test inside ads


Solution

  • You can select all the nodes inside class all_ads as follow:-

    var res = div.SelectNodes(".//div[@class='all_ads ads__item']");
    

    .//div[@class='all_ads ads__item'] This will select all the nodes inside all_adswhich has class ads_item.