I want to get a div from my html document that has no id or name, but has a unique style tag.
Here is what I tried:
foreach (HtmlNode node in myDocument.DocumentNode.DescendantNodes())
{
if (node.OuterHtml.Contains("div"))
{
HtmlAttribute att = node.Attributes["style"];
if (att != null)
{
if (att.ToString() == "font-size:16px;padding:4px 8px 0")
{
targetDiv = node;
}
}
}
}
First I got all of the nodes in document, then I tried to filter out only the divs using:
if (node.OuterHtml.Contains("div"))
However, this isn’t actually filtering out the divs but selecting any tag which has div in it. What is the proper way to do this?
Try XPath: