why returning the same html tag attribute every time?
See the question and my original answer on StackOverflowI'm not familiar with F#, but here is the C# equivalent:
HtmlDocument doc = LoadMyDocument();
foreach (HtmlNode tr in doc.DocumentNode.SelectNodes("tr"))
{
string title = null;
HtmlNode titleNode = tr.SelectSingleNode(".//p");
if (titleNode != null)
{
title = titleNode.GetAttributeValue("title", null);
}
string anchor = null;
HtmlNode anchorNode = tr.SelectSingleNode(".//a");
if (anchorNode != null)
{
anchor = anchorNode.InnerText;
}
string value = null;
HtmlNode valueNode = tr.SelectSingleNode("td[last()]");
if (valueNode != null)
{
value = valueNode.InnerText.Trim();
}
Console.WriteLine("title=" + title);
Console.WriteLine("anchor=" + anchor);
Console.WriteLine("value=" + value);
}
The main problem you have is because you use a "//p" expression which starts off root, instead of a ".//p" which starts from the current node.