HtmlAgilityPack HtmlNodeCollection returning NULL , shouldn't

c# html-agility-pack xpath

Question

I made a simple program for fetching youtube users in comments. This is the code

string html;
        using (var client = new WebClient())
        {
            html = client.DownloadString("http://www.youtube.com/watch?v=ER5EnjskCvE");
        }
        HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
        doc.LoadHtml(html);
        List<string> data = new List<string>();
        HtmlNodeCollection nodeCollection = doc.DocumentNode.SelectNodes("//*[@id='comments-view']/ul[1]/li[1]/a/span/span/span/span/img");
        foreach (HtmlNode node in nodeCollection)
        {
            data.Add(node.GetAttributeValue("alt",null));
        }

But i have a problem that my nodeCollection is returning null. For the XPath i used copy XPath option in chrome under F12

Popular Answer

try this replace "*" , "div"
"/html/body//div[@id='comments-view']/ul[1]/li[1]/a/span/span/span/span/img"



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow