1

I'm trying to get a third webPage content in my project with HtmlAgilityPack. The first two, works perfectly fine and i can get the content that i want. But each time i try with a third website (In a different class), a system.NullReference Exception is thrown and i don't understand why, the class that i'm looking for is on the website, i've tried to just get the body Element by a basic code but it seems that i can not have more than two websites in my project

 private void extractNomsJoueurs(HtmlAgilityPack.HtmlDocument doc)
 {
            var links = doc.DocumentNode.SelectNodes("//*[contains(@class, 'bets ml')]");
            var names = links.Elements("span");
            foreach (var name in names)
            {
                listNames1Bet777.Add(name.InnerText);
            }
            for (int i = 0; i < listNames1Bet777.Count(); i++)
            {
                if (i % 2 == 0)
                {
                    listNames2Bet777.Add(listNames1Bet777[i]);
                }
            }
            foreach (string name in listNames1Bet777)
            {
                listNames1Bet777.Remove(name);
            }
 }

Exception thrown: 'System.NullReferenceException' in BotProper.exe
links was null.

The exception thrown

PS: Apologies for my bad english.

stuartd
  • 70,509
  • 14
  • 132
  • 163
lioleveau
  • 518
  • 1
  • 6
  • 23
  • Hi, welcome to Stack Overflow! For future reference we prefer you to post your code as text rather than as an image. – stuartd Feb 26 '18 at 16:40
  • Yup sorry, first post ! – lioleveau Feb 26 '18 at 16:44
  • [This question](https://stackoverflow.com/questions/8619724/htmlagilitypack-documentnode-selectnodes-returns-null-shouldnt) might help – stuartd Feb 26 '18 at 16:46
  • thank you, but the guy had just forgot to load the url in his UnitTest :) – lioleveau Feb 26 '18 at 16:50
  • I missed that comment, the one I noted says _"When no nodes are (legitimately) found, then (as you know) you get null instead of an empty enumerable."_ … – stuartd Feb 26 '18 at 18:09

0 Answers0