HTML agility pack's wildcard search in the node selector

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?

1
2
5/16/2012 4:41:21 PM

Accepted Answer

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

node = doc.DocumentNode.SelectSingleNode(".//div[contains(@style, 'PADDING-BOTTOM:')]");
4
5/16/2012 4:45:04 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