我如何在Discord聊天中解析HTML表内容?discord.net c#



美好的一天,我想从网站表中解析内容。在网站上,有一个排名最高的每周EXP播放器的排名。每周我想超越最佳的20名球员。现在我有以下代码:

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"); 
            });

,但它没有给我任何东西,那为什么我错了呢?更好的是,我可以做一个数组(以前有过它,但没有起作用),我可以说:"我只想要第一个<tr>(#),第二个<tr>(名称)和例如第七<tr>(Clanname)。

,但我失败了阵列 将这些TR内容解析至Discord:/

表中的1行是:

<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>

我认为表中的内容是动态生成的,页面中的某些JavaScript代码会生成它。但是,在文档加载后加载了此动态内容。因此,当您下载页面时,您将无法获得所有内容。
您可以在这里阅读更多有关它的信息:
htmlagilitypack和动态内容问题
WebClient不会完全下载网页
WebClient中动态生成的HTML代码
如何从网页中提取动态AJAX内容
使用C#

在HTML文档中的JavaScript动态生成的刮擦数据

最新更新