This project has moved. For the latest updates, please go here.

XPath Expression Not Working...

Topics: User Forum
Aug 26, 2010 at 7:39 AM
Edited Aug 26, 2010 at 7:40 AM

Hi all,

I know it may be of my noobness in XPath, but let me ask to make sure, cuz I've googled enough.

I have a website and wanna get the news headings from it: (it is Persian)

Using FireBug and FireXpath extensions under firefox and by hand I extract and test multiple Xpath expressions that matches the headings, such as:

  • html/body/div[2]/div[2]/div[2]/div[*]/div[2]/a/div[2]
  • .//*[@class="topnewsinfotitle "]
  • .//div[@class="topnewsinfotitle "]

I also tested these using XPather extension and they seem to work pretty well, but when I get to test them... the SelectNodes returns null!

Any clue or hint?

here is a chunk of the code:



            HtmlAgilityPack.HtmlWeb w = new HtmlAgilityPack.HtmlWeb();
            HtmlAgilityPack.HtmlDocument doc = w.Load("");
            HtmlAgilityPack.HtmlNodeCollection nc = doc.DocumentNode.SelectNodes(".//div[@class=\"topnewsinfotitle \"]");
            listBox2.Items.Add(nc.Count+" Items selected!");

            foreach (HtmlAgilityPack.HtmlNode node in nc) {



Aug 28, 2010 at 6:00 AM


Aug 30, 2010 at 5:58 PM

I would use

"//div[@class='topnewsinfotitle ']"

I'm not sure is there difference between """ and "'", but it's simpler. I used similar expressions many times and they worked.