Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML agility pack get all divs with class

I am trying to scape a complicated HTMl. I need to get some text from div's with certain class.

What I am trying to do is have the html agility pack to go over the whole html and find all divs whos class contains "listevent" and return me those.

When I searched online I found out that If I map it , it is possible, but some of these divs are under somemany divs so trying to find some easy way.

The HTML looks like this

<div>
    <div>
       <table>
          <tr>
            <td>
              <div class="thisone listevent"></td>
            <td>
              <div class="thisone listevent"></td>
           </tr>
         </table>
     </div>
 </div>
like image 448
Burak Gazi Avatar asked Feb 10 '14 12:02

Burak Gazi


1 Answers

You could use SelectNodes method

foreach(HtmlNode div in document.DocumentNode.SelectNodes("//div[contains(@class,'listevent')]"))
{
}

If you are more familiar with css style selectors, try fizzler and do this

document.DocumentNode.QuerySelectorAll("div.listevent"); 
like image 164
Mike Koder Avatar answered Oct 14 '22 10:10

Mike Koder