1

I want to extract not the whole web-page but only text from one class, I haven't found how to do this for my code. I want text from td class="result-neutral" this is html code:

<td class="result-neutral" xseid="xz1nBfht"><a href="/hockey/russia/khl/ska-st-petersburg-metallurg-magnitogorsk-xz1nBfht/">3 - 2 </a></td>

Now I have sych a C# code(Info is the name of a textbox):

 HtmlAgilityPack.HtmlDocument doc = new HtmlDocument();
        HtmlWeb hw = new HtmlWeb();
        doc = hw.Load("http://www.sportstats.com/hockey/russia/detail/ska-st-petersburg-zVJwe4ER/");
       var nodes = doc.DocumentNode.Descendants("td");
 string result = "";
        foreach (var item in nodes)
        {
            result += item.InnerText+Environment.NewLine;
        }
        Info.Text = result;

    }

To be honest, I'd better get the score, which in the example above is 3-2

David Shepard
  • 181
  • 2
  • 10
  • You may try the following link: https://stackoverflow.com/questions/13771083/html-agility-pack-get-all-elements-by-class – The KNVB Jun 19 '17 at 09:02

1 Answers1

0

I guess that site is using AJAX to load the scores so it will not be available for HTMLAgilityPack when you use their .Load().

Perhaps you can use WebBrowser object in C# to load the page first and then use HAP to load the content. There are ton of examples about this.

Hope it helps!

Hung Cao
  • 3,130
  • 3
  • 20
  • 29