我正在製作一個從網站獲取足球統計數據並存儲它的程序。問題是網站在HTML代碼中存儲不同狀態的方式沒有區別。從網站C#如何判斷HTML標籤的區別?
代碼片段:
// First Team
<td style="background-color:#79a6ca;"><!-- --></td>
<td class="t_c" style="border-right:1px #dddddd solid; background-color:#ebf2f7;">2</td>
<td style="padding-left:10px; background-color:#ebf2f7;"><img src="/assets/images/logo/participants/16x16/8113.png" width="16" height="16" border="0" alt="FC Midtjylland" title="FC Midtjylland" /> <a href="/fodboldklubber/fc-midtjylland/" style="font-weight:bold; color:#333;">FC Midtjylland</a></td>
<td class="t_c" style="background-color:#ebf2f7;">14</td>
<td class="t_c" style="background-color:#ebf2f7;">8</td>
<td class="t_c" style="background-color:#ebf2f7;">3</td>
<td class="t_c" style="background-color:#ebf2f7;">3</td>
<td class="t_c" style="border-left:1px #dddddd solid; border-right:1px #dddddd solid; background-color:#ebf2f7;">19 - 10</td>
<td class="t_c" style="font-weight:bold; background-color:#ebf2f7;">27</td>
</tr>
// Second team
<tr data-toggle="tooltip" data-placement="left" title="Europa League kvalifikation">
<td style="background-color:#79a6ca;"><!-- --></td>
<td class="t_c" style="border-right:1px #dddddd solid; background-color:#ebf2f7;">3</td>
<td style="padding-left:10px; background-color:#ebf2f7;"><img src="/assets/images/logo/participants/16x16/8595.png" width="16" height="16" border="0" alt="Brøndby IF" title="Brøndby IF" /> <a href="/fodboldklubber/broendby-if/" style="font-weight:bold; color:#333;">Brøndby IF</a></td>
<td class="t_c" style="background-color:#ebf2f7;">14</td>
<td class="t_c" style="background-color:#ebf2f7;">7</td>
<td class="t_c" style="background-color:#ebf2f7;">3</td>
<td class="t_c" style="background-color:#ebf2f7;">4</td>
<td class="t_c" style="border-left:1px #dddddd solid; border-right:1px #dddddd solid; background-color:#ebf2f7;">24 - 17</td>
<td class="t_c" style="font-weight:bold; background-color:#ebf2f7;">24</td>
</tr>
我使用Web客戶端下載頁面,MatchCollection搜索所需的圖案。 計劃是將值寫入字符串數組。
我已經試過JStromwick的例子,它的工作類型,但它並沒有停止後,團隊。它也需要下一個團隊。我如何解決這個問題。我可以放櫃檯嗎?
到目前爲止我的代碼:
string[] superLigaHold = new string[] { "FC Midtjylland", "Brøndby IF" };
for (int i = 0; i < superLigaHold.Length; i++)
{
string teamPattern = "<img src.*? width=\"16\" height=\"16\" border=\"0\" alt=\"" + superLigaHold[i] + "\" title=\"" + superLigaHold[i] + "\" />";
MatchCollection team = Regex.Matches(webPage, teamPattern, RegexOptions.Singleline);
if (team.Count > 0)
{
var gameStats = Regex.Matches(webPage, "<td.+?>(\d+).*");
string gamesTotal = gameStats[0].Groups[1].Value;
string gamesWon = gameStats[1].Groups[1].Value;
string gamesDraw = gameStats[2].Groups[1].Value;
string gamesLost = gameStats[3].Groups[1].Value; }
沒有人有我怎樣才能解決這個問題有什麼建議?
我不是一個C#程序員但我不知道這是可能的,如果你只是得到該HTML,沒有更多:/ ..是這個HTML總是在這個順序? –