-2

enter image description here

var webGet = new HtmlWeb(); var document = webGet.Load("https://www.binance.com/en/legacy/LINK_USDT");

        var titles = document.DocumentNode.SelectNodes("//*[@id='__next']/div/main/div/div/div[2]/div[1]/div[1]/div[2]/div[1]/div[3]/div[1]/strong");
        
        foreach (var title in titles)
        {
            Console.WriteLine(title.InnerText);
        }
Fildor
  • 14,510
  • 4
  • 35
  • 67
  • Before going into the loop, check if `titles` is null. – Fildor Oct 15 '20 at 09:38
  • 1
    Your problem is that this site populates the DOM using JavaScript. If you view the source (not the DOM, but the page source), you'll see that the XPath you try doesn't exist, and `titles` is therefore `null`. The site looks like a stock tracker which you want to scrape. You either need to embed or emulate a browser in your application so the JavaScript gets executed, or you use the site's API (if any) to retrieve relevant data programatically. Just asking how to do _that_ would make your question too broad; research those terms for yourself and attempt to solve it. – CodeCaster Oct 15 '20 at 09:41

1 Answers1

1

In short this means this code here:

var titles = document.DocumentNode.SelectNodes("//*[@id='__next']/div/main/div/div/div[2]/div[1]/div[1]/div[2]/div[1]/div[3]/div[1]/strong");

Is not getting any results, so your XPath maybe incorrect for what you are looking for.

anon
  • 816
  • 5
  • 17