HTML agility pack get all divs with class

c# html-agility-pack

Question

I'm attempting to escape a challenging HTMl. I need to extract certain text from divs that have a particular class.

I want the HTML Agility Pack to search the whole html file for any divs whose class includes "listevent" and return them to me.

I learned from my web research that if I map it, it is feasible, however some of these divs are nested beneath other divs, therefore I'm looking for a simple solution.

The HTML appears as follows.

<div>
    <div>
       <table>
          <tr>
            <td>
              <div class="thisone listevent"></td>
            <td>
              <div class="thisone listevent"></td>
           </tr>
         </table>
     </div>
 </div>
1
8
2/10/2014 1:01:48 PM

Accepted Answer

You could utilizeSelectNodes method

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

Try fizzler and complete this if you are more comfortable with CSS style selectors.

document.DocumentNode.QuerySelectorAll("div.listevent"); 
16
2/10/2014 1:36:38 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow