HTML Agility Pack Select Nodes with Multiple Attributes

c# html html-agility-pack parsing

Question

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!

Accepted Answer

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;


Related

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