Wildcard search in the node selector with HTML agility pack


this is the part of my code

<div style="PADDING-BOTTOM: 4px"> blah </div>
<div style="PADDING-BOTTOM: 2px"> blah </div>

how can I select 2nd and 3rd divs into 'node.SelectNodes' ?

HtmlNode node = doc.DocumentNode.SelectSingleNode(".//div[@style='PADDING-BOTTOM: 2px']");

Can I do some sort of wilcard search for 2px and 4px or any other px?

Accepted Answer

You can use contains() to do a string-in-string match.

node = doc.DocumentNode.SelectSingleNode(".//div[contains(@style, 'PADDING-BOTTOM:')]");

Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why