【发布时间】:2017-05-11 10:33:31
【问题描述】:
美好的一天, 我想解析网站表中的内容。 在网站上有一个顶级每周经验玩家排名。并且使用命令 ~weekly 我想击败最好的 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>(名字)和例如第 7 个<tr>(氏族名称)。
但是我失败了数组+将这些 tr 内容解析为不和谐:/
例如表中的 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>
【问题讨论】:
-
下载的文本不包含
值。看一下 html 变量的内容,你会看到 . -
有td属性:/
-
但是它们是空的!
-
但是为什么呢?正如您在 html 代码中看到的,td 不是空的
-
我不知道为什么。你只需要找到下载正确内容的方法,然后你就可以想到如何解析html并获得你想要的。
标签: c# html parsing discord discord.net