Wildcard search in the node selector with HTML agility pack

c# html-agility-pack winforms

Question

this is the part of my code

<div>
<div style="PADDING-BOTTOM: 4px"> blah </div>
<div style="PADDING-BOTTOM: 2px"> blah </div>
<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 with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why