I would try to insert the spans into a dictionary, assuming that the span IDs are unique:
Dictionary<string, HtmlNode> spans = document.DocumentNode.Descendants("span")
.Where(node => node.Attributes["id"] != null)
.ToDictionary(node => node.Attributes["id"].Value);
Now you can get the spans quickly with:
HtmlNode span;
if (spans.TryGetValue("apple", out span)) {
string text = span.InnerText.Trim();
}
Or getting the inner text directly:
Dictionary<string, string> texts = document.DocumentNode.Descendants("span")
.Where(node => node.Attributes["id"] != null)
.ToDictionary(node => node.Attributes["id"].Value,
node => node.InnerText.Trim());
Now you can get the texts quickly with:
string text;
if (texts.TryGetValue("apple", out text)) {
Console.WriteLine(text);
}
Or if you are sure that the span IDs exist:
string apple = texts["apple"];
string orange = texts["orange"];