From a0e15514e34ca344f275f6672aff1299e6e8c666 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Sun, 15 Jan 2023 19:00:27 -0600 Subject: [PATCH] Better scraping of multiplayer counts from PCGamingWiki --- LANCommander.PCGamingWiki/PCGamingWikiClient.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/LANCommander.PCGamingWiki/PCGamingWikiClient.cs b/LANCommander.PCGamingWiki/PCGamingWikiClient.cs index 43cd630..24644df 100644 --- a/LANCommander.PCGamingWiki/PCGamingWikiClient.cs +++ b/LANCommander.PCGamingWiki/PCGamingWikiClient.cs @@ -56,13 +56,20 @@ namespace LANCommander.PCGamingWiki if (multiplayerTable == null) return null; + var multiplayerRows = multiplayerTable.SelectNodes(".//tr[contains(@class, 'table-network-multiplayer-body-row')]"); var multiplayerAbbrs = multiplayerTable.SelectNodes(".//abbr"); var multiplayerCounts = multiplayerTable.SelectNodes(".//td[contains(@class, 'table-network-multiplayer-body-players')]"); - for (int i = 0; i < multiplayerAbbrs.Count; i++) + foreach (var row in multiplayerRows) { - var type = multiplayerAbbrs[i].InnerText; - var players = multiplayerCounts[i].InnerText; + var abbr = row.SelectNodes(".//abbr"); + var count = row.SelectNodes(".//td[contains(@class, 'table-network-multiplayer-body-players')]"); + + if (abbr == null || count == null) + continue; + + var type = abbr[0].InnerText; + var players = count[0].InnerText; int playerCount = 0;