2

How would I go about selecting only the week number in this h3 and not the span tag inside it?

Selecting just the H3 including the span results in some ascii text being added to the resulting messagebox.

Result:

 Week 1

Source document:

<h3>
<span> </span>Week 1</h3>

Code:

private void getWeekNumber(string url)
{
    HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();

    htmlDoc.Load(new System.IO.StringReader(url));

    foreach (HtmlAgilityPack.HtmlNode h3 in htmlDoc.DocumentNode.SelectNodes("//h3"))
    {
        MessageBox.Show(h3.InnerText);
    }
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
deepseapanda
  • 3,717
  • 8
  • 32
  • 39

1 Answers1

0

Try using RemoveChild(...) to remove the span node before you show the messagebox.

For more info:

html agility pack remove children

Community
  • 1
  • 1
Ian Jacobs
  • 5,456
  • 1
  • 23
  • 38