Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Agility Pack Select Nodes with Multiple Attributes

This might be a simple and stupid question but I can't seem to find anything on selecting a node that has multiple attribute. In my case it is a specific class and a specific style.

Here is a snippet from the HTML I am working with.

<div class="buying" style="padding-bottom: 0.75em;">
<span class="availGreen">Blah Blah</span><br /> Blah Blah Blah<b>Sold By</b>.
</div>

There are many different instances of the class "buying" but only one instance of the div that includes both the buying class and the style="padding-bottom: 0.75em attributes. I am trying to grab the text inside the tag.

Here is what I have tried but I got nowhere:

SelectSingleNode("//div[@class='buying'][@style='padding-bottom: 0.75em;']/b").InnerText;

And also:

SelectSingleNode("//div[@class='buying' @style='padding-bottom: 0.75em;']/b").InnerText;

Neither of these produced any results but I am not sure what else is correct.

Any help is much appreciated!

like image 968
Reg Avatar asked Feb 23 '13 19:02

Reg


1 Answers

Try joining them with and (I believe that's the correct XPath way of selecting multiple attributes):

SelectSingleNode("//div[@class='buying' and @style='padding-bottom: 0.75em;']/b").InnerText;
like image 159
mgibsonbr Avatar answered Oct 09 '22 12:10

mgibsonbr