private List <Tater> GetLatestTaters() { List <Tater> latestTaters = new List <Tater>(); string url = @"http://hosted.stats.com/mlb/scoreboard.asp?day=" + _dateString; string fullHtml = WebClient.DownloadString(url); foreach (Match row in Regex.Matches(fullHtml, @"<tr\s+class=""shsGameHomeRuns"".*?</tr>", RegexOptions.IgnoreCase | RegexOptions.Singleline)) { foreach (Match m in Regex.Matches(row.ToString(), @"<a\s+.*?id=(\d+)[^>]*>([^<]*)<[^>]*>\s*(\d+)?", RegexOptions.IgnoreCase | RegexOptions.Singleline)) { long playerId = long.Parse(m.Groups[1].ToString()); string batter = m.Groups[2].ToString(); decimal taters = m.Groups[3].Length > 0 ? decimal.Parse(m.Groups[3].ToString()) : 1; TaterStandingsRow taterStandingsRow = _standings.FirstOrDefault(x => x.Batters.Contains(playerId)); string owner = taterStandingsRow != null ? taterStandingsRow.Owner : ""; Tater existingTater = latestTaters.FirstOrDefault(x => x.PlayerId.Equals(playerId)); if (existingTater != null) { existingTater.Taters += taters; } else { latestTaters.Add(new Tater(playerId, batter, owner, taters)); } } } return(latestTaters); }
private void GetStandings() { List <TaterStandingsRow> latestStandings = new List <TaterStandingsRow>(); const string url = @"http://pools.stats.com/homer/homer_draft.html"; string fullHtml = WebClient.DownloadString(url); Match tab = Regex.Match(fullHtml, @"Total Tater Leaders.*?</table>", RegexOptions.IgnoreCase | RegexOptions.Singleline); foreach (Match row in Regex.Matches(tab.ToString(), @"<tr\s+bgcolor.*?<font.*?>(.*?)<.*?<font.*?>(?:[^<]*\s)?(.*?)<.*?<font.*?>(\d+)\s+\((\d+).*?(\?id=.*?</tr>)", RegexOptions.IgnoreCase | RegexOptions.Singleline)) { TaterStandingsRow newRow = new TaterStandingsRow(row.Groups[2].ToString().ToUpper(), int.Parse(row.Groups[3].ToString())); foreach (Match plyr in Regex.Matches(row.Groups[5].ToString(), @"\?id=(\d+)", RegexOptions.IgnoreCase | RegexOptions.Singleline)) { newRow.Batters.Add(int.Parse(plyr.Groups[1].ToString())); } latestStandings.Add(newRow); } _standings = latestStandings; }