How I can parse HTML table content in Discord Chat? Discord.NET C#

3k views Asked by At

Good day, I want to parse the content from a websites table. On the Website there is a Ranking of Top Weekly Exp Players. And with the command ~weekly i want to outpot the best 20 players. For now I have the following Code:

commands.CreateCommand("weekly")
            .Do(async (e) =>
            {
                WebClient webClient = new WebClient();
                string html = webClient.DownloadString("http://combatarms.nexon.net/de/ranking/player");

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);

                foreach (var cell in doc.DocumentNode.SelectNodes("//table[@class='ranking_tbl']/tr/td"))
                {
                    await e.Channel.SendMessage(cell.InnerText);
                }

               // await e.Channel.SendMessage("test"); 
            });

But it doesn't shows me anything, so why im wrong? A better thing would be that I can do an array (had it before but doesn't worked) where I can say "I only want the first <tr> (the #), the second <tr> (the name) and for example the 7th <tr> (the Clanname).

But I fail with array + parsing these tr content to discord :/

For example 1 row in the table is:

<table class="ranking_tbl" summary="">
            <colgroup>
                <col width="80">
                <col width="250">
                <col width="100">
                <col width="150">
                <col width="100">
                <col width="100">
                <col width="280">
            </colgroup>
            <thead>
                <tr>
                    <th></th>
                    <th>Name </th>
                    <th>Rang </th>
                    <th>EP </th>
                    <th>KDR </th>
                    <th>Land </th>
                    <th>Clan- </th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td class="cell_left">1</td>
                    <td><a href="/de/profile/player/RADICALIST">RADICALIST</a></td>
                    <td><img src="http://caimage.nexoneu.com/Rank/rank_51.gif" alt=""></td>
                    <td>5.219.130</td>
                    <td>1,46</td>
                    <td><img src="http://caimage.nexoneu.com/Web_site/Main/img/flag/SI.png" alt=""></td>
                    <td><a href="/de/clan/profile/Jasmine%20Thompson">Jasmine Thompson</a></td>
                </tr>
1

There are 1 answers

0
Pedro Perez On

I think content in the table is generated dynamically, some javascript code in the page generates it. But this dynamic content is loaded after the document loads. So when you download the page you can't get all the content.
You can read more about it here:
htmlagilitypack and dynamic content issue
webclient doesn't download the web page completely
Load dynamically generated HTML Code in WebClient
How to extract dynamic ajax content from a web page
Scraping data dynamically generated by JavaScript in html document using C#