1

I am trying to get the InnerText of a particular node with the following xpath /html/body/center/table/tbody/tr[5]/td[3]/font/font/span by using the following
doc.DocumentNode.SelectSingleNode("/html/body/center/table/tbody/tr[5]/td[3]/font/font/span").InnerText

But instead it is returning me the InnerText with the following xpath /html/body/center/form/table/tbody/tr[5]/td[3]/font/font/span

Am I making any mistake? Do I have to be more specific with the Xpath? If so, please help me by specifying how to be more specific.

Vignesh PT
  • 624
  • 12
  • 28

1 Answers1

2

You're running into a known behavior with regards to the handling of tags to fix incorrectly written HTML. There is a bug tracking this on the HTML Agility Pack website and luckily, there is a workaround for this.

        HtmlDocument doc = new HtmlDocument();
        // v== Add this line before loading a document
        HtmlNode.ElementsFlags.Remove("form"); 
        doc.Load("doc.html");
jessehouwing
  • 106,458
  • 22
  • 256
  • 341