C# html agility pack get elements by class name

Ofer Gozlan picture Ofer Gozlan · Apr 19, 2016 · Viewed 28.5k times · Source

I'm trying to get all the divs that their class contains a certain word:

<div class="hello mike">content1</div>
<div class="hello jeff>content2</div>
<div class="john">content3</div>

I need to get all the divs that their class contains the word "hello". Something like this:

resultContent.DocumentNode.SelectNodes("//div[@class='hello']"))

how can i do it with agility pack?

Answer

Ofer Gozlan picture Ofer Gozlan · Apr 19, 2016

I got it:

resultContent.DocumentNode.SelectNodes("//div[contains(@class, 'hello')]"))